public static void Main(string[] args) { var host = BuildWebHost(args); // Seed Database on Startup : using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; DbSeed.Initialize(services).Wait(); } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env, ApplicationDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseAuthentication(); app.UseMvc(); DbSeed.Initialize(dbContext); dbContext.Database.EnsureCreated(); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <Inlämningsuppgift_1_aspContext>(); context.RemoveRange(); context.SaveChanges(); DbSeed.Initialize(context); } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <SchoolContext>(); DbSeed.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); DbSeed.Initialize(context, roleManager, userManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }