public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { //var services = scope.ServiceProvider; //var context = services.GetRequiredService<OssDbContext>(); //try //{ // var userManager = services.GetRequiredService<UserManager<UserDbModel>>(); // var roleManager = services.GetRequiredService<RoleManager<IdentityRole>>(); // var tmp = services.GetRequiredService<UserService>(); // Initializer initializer = new Initializer(); // await initializer.RoleInitializer(context, roleManager); // await initializer.UserInitializer(context, userManager); // await initializer.ItemInitializer(context); //} //catch (Exception e) //{ // var logger = services.GetRequiredService<ILogger<Program>>(); // logger.LogError(e, "An error occurred while seeding the database."); //} var services = scope.ServiceProvider; await ContextInitializer.Initialize(services); } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); using (var scope = app.ApplicationServices.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <SchoolContext>(); ContextInitializer.Initialize(context); } } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public async Task Should_Call_DietDecisionMaker_Allow_Banana(string message) { using (var context = new DietContext(_options)) { ContextInitializer.Initialize(context); var textMessageProcessor = new TextMessageProcessor(context, new NullLogger <TextMessageProcessor>()); var result = await textMessageProcessor.Process(message); Assert.False(string.IsNullOrEmpty(result.Content)); } }
protected void Application_Start() { ContextInitializer.Initialize(); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //Populate Feed Repository FeedRepositoryConfig.ConsumeFeed(); }
public SqliteWrapper(bool seed = false) { connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); dbContextOptions = new DbContextOptionsBuilder <MonilyzerContext>() .UseSqlite(connection) .Options; // Create the schema using (var context = GetContext()) { context.Database.EnsureCreated(); if (seed) { ContextInitializer.Initialize(context); } } }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { try { var context = scope.ServiceProvider.GetRequiredService <DietContext>(); ContextInitializer.Initialize(context); } catch (System.Exception ex) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider) { // app.UseCors(options => options.WithOrigins("http://localhost:5000/").AllowAnyMethod().AllowAnyHeader()); app.UseCors("AllowAllHeaders"); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); try { var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope(); var context = scope.ServiceProvider.GetService <eFolioDBContext>(); var userManager = serviceProvider.GetRequiredService <UserManager <UserEntity> >(); var contextForAuth = serviceProvider.GetRequiredService <AuthDBContext>(); context.Database.Migrate(); contextForAuth.Database.Migrate(); ContextInitializer.Initialize(context, new Elastic.ElasticSearch()); ContextInitializerForAuth.Initialize(contextForAuth, userManager).Wait(); } catch (Exception ex) { var logger = serviceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while seeding the database."); } //using (var scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope()) //{ // var context = scope.ServiceProvider.GetService<eFolioDBContext>(); // context.Database.Migrate(); // ContextInitializer.Initialize(context); //} } app.UseIdentityServer(); app.UseAuthentication(); app.UseMvc(); }