private static void RegisterModuleDbContext <TDbContext>(string moduleAssembly, IInstallationProvider installationProvider, IServiceCollection serviceCollection) where TDbContext : DbContext { serviceCollection.AddDbContext <TDbContext>( (internalServiceProvider, dbContextOptionBuilder) => { //dbContextOptionBuilder.UseInternalServiceProvider(sp); installationProvider.GetDbContextOptionsBuilder <TDbContext>(dbContextOptionBuilder, moduleAssembly); }); }
public static IServiceCollection AddDeviserPlatform(this IServiceCollection services, IConfiguration configuration) { services.AddSingleton <IInstallationProvider, InstallationProvider>(); services.AddSingleton <ISiteSettingRepository, SiteSettingRepository>(); var sp = services.BuildServiceProvider(); IInstallationProvider installationProvider = sp.GetRequiredService <IInstallationProvider>(); SharedObjects.ServiceProvider = sp; //if (installationProvider.IsPlatformInstalled) //{ services.AddDbContext <DeviserDbContext>( (internalServiceProvider, dbContextOptionBuilder) => { //dbContextOptionBuilder.UseInternalServiceProvider(sp); installationProvider.GetDbContextOptionsBuilder(dbContextOptionBuilder); }); //} services.AddIdentity <User, Role>() .AddEntityFrameworkStores <DeviserDbContext>() .AddDefaultTokenProviders(); MapperConfig.CreateMaps(); sp = services.BuildServiceProvider(); //Add framework services. //services.AddDbContext<DeviserDbContext>(options => // options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Deviser.WI"))); if (installationProvider.IsPlatformInstalled) { var siteSettingRepository = sp.GetService <ISiteSettingRepository>(); //sp.GetService<ISiteSettingRepository>(); var siteSettings = siteSettingRepository.GetSettings(); var enableFacebookAuth = siteSettings.FirstOrDefault(s => s.SettingName == "EnableFacebookAuth").SettingValue; var facebookAppId = siteSettings.FirstOrDefault(s => s.SettingName == "FacebookAppId").SettingValue; var facebookAppAppSecret = siteSettings.FirstOrDefault(s => s.SettingName == "FacebookAppSecret").SettingValue; var enableGoogleAuth = siteSettings.FirstOrDefault(s => s.SettingName == "EnableGoogleAuth").SettingValue; var googleClientId = siteSettings.FirstOrDefault(s => s.SettingName == "GoogleClientId").SettingValue; var googleClientSecret = siteSettings.FirstOrDefault(s => s.SettingName == "GoogleClientSecret").SettingValue; var enableTwitterAuth = siteSettings.FirstOrDefault(s => s.SettingName == "EnableTwitterAuth").SettingValue; var twitterConsumerKey = siteSettings.FirstOrDefault(s => s.SettingName == "TwitterConsumerKey").SettingValue; var twitterConsumerSecret = siteSettings.FirstOrDefault(s => s.SettingName == "TwitterConsumerSecret").SettingValue; if (!string.IsNullOrEmpty(enableFacebookAuth) && bool.Parse(enableFacebookAuth.ToLower())) { services.AddAuthentication().AddFacebook(facebookOptions => { facebookOptions.AppId = facebookAppId; facebookOptions.AppSecret = facebookAppAppSecret; }); } if (!string.IsNullOrEmpty(enableTwitterAuth) && bool.Parse(enableTwitterAuth.ToLower())) { services.AddAuthentication().AddTwitter(twitterOptions => { twitterOptions.ConsumerKey = twitterConsumerKey; twitterOptions.ConsumerSecret = twitterConsumerSecret; }); } if (!string.IsNullOrEmpty(enableGoogleAuth) && bool.Parse(enableGoogleAuth.ToLower())) { services.AddAuthentication().AddGoogle(googleOptions => { googleOptions.ClientId = googleClientId; googleOptions.ClientSecret = googleClientSecret; }); } } services.Add(ServiceDescriptor.Transient <IConfigureOptions <MvcOptions>, SerializerSettingsSetup>()); RegisterModuleDependencies(services); services .AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddRazorOptions(options => { options.ViewLocationExpanders.Add(new ModuleLocationRemapper()); }) .AddControllersAsServices(); services.AddSignalR(); services.AddSession(); // Add application services. services.AddTransient <IEmailSender, MessageSender>(); services.AddTransient <ISmsSender, MessageSender>(); services.TryAddSingleton <ObjectMethodExecutorCache>(); services.TryAddSingleton <ITypeActivatorCache, TypeActivatorCache>(); return(services); }