public static NSCRegDbContext CreateSqliteDbContext() { var ctx = new NSCRegDbContext(GetContextOptions()); ctx.Database.EnsureCreated(); NscRegDbInitializer.CreateViewsProceduresAndFunctions(ctx, ConnectionProvider.InMemory); return(ctx); }
/// <summary> /// Application Configuration Method /// </summary> /// <param name="app">App</param> /// <param name="loggerFactory">loggerFactory</param> // ReSharper disable once UnusedMember.Global public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { #pragma warning disable CS0618 // Type or member is obsolete loggerFactory .AddConsole(Configuration.GetSection("Logging")) .AddDebug() .AddNLog(); #pragma warning restore CS0618 // Type or member is obsolete _loggerFactory = loggerFactory; var localization = Configuration.GetSection(nameof(LocalizationSettings)); Localization.LanguagePrimary = localization["DefaultKey"]; Localization.Language1 = localization["Language1"]; Localization.Language2 = localization["Language2"]; Localization.Initialize(); var supportedCultures = new List <CultureInfo>(new[] { new CultureInfo(Localization.LanguagePrimary), new CultureInfo(Localization.Language1), new CultureInfo(Localization.Language2) }); app.UseRequestLocalization(new RequestLocalizationOptions() { DefaultRequestCulture = new RequestCulture(Localization.LanguagePrimary), SupportedCultures = supportedCultures, SupportedUICultures = supportedCultures }); app.UseStaticFiles(); #pragma warning disable CS0618 // Type or member is obsolete app.UseIdentity() #pragma warning restore CS0618 // Type or member is obsolete .UseMvc(routes => routes.MapRoute( "default", "{*url}", new { controller = "Home", action = "Index" })); var provider = Configuration .GetSection(nameof(ConnectionSettings)) .Get <ConnectionSettings>() .ParseProvider(); var reportingSettingsProvider = Configuration .GetSection(nameof(ReportingSettings)) .Get <ReportingSettings>(); using (var serviceScope = app.ApplicationServices.CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetService <NSCRegDbContext>(); if (provider == ConnectionProvider.InMemory) { dbContext.Database.OpenConnection(); dbContext.Database.EnsureCreated(); } else { dbContext.Database.SetCommandTimeout(600); dbContext.Database.Migrate(); } if (CurrentEnvironment.IsStaging()) { NscRegDbInitializer.RecreateDb(dbContext); } NscRegDbInitializer.CreateViewsProceduresAndFunctions( dbContext, provider, reportingSettingsProvider); NscRegDbInitializer.EnsureRoles(dbContext); NscRegDbInitializer.EnsureEntGroupTypes(dbContext); if (provider == ConnectionProvider.InMemory) { NscRegDbInitializer.Seed(dbContext); } } ElasticService.ServiceAddress = Configuration["ElasticServiceAddress"]; ElasticService.StatUnitSearchIndexName = Configuration["ElasticStatUnitSearchIndexName"]; }