// 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.UseDeveloperExceptionPage(); } DBSeeder.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider); app.UseAuthentication(); app.UseMvc(); }
private static void SeedDatabase(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDBContext>(); DBSeeder.Initialize(context, services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError("An error occurred while seeding the database"); } } }