private static void RunSeeding(IWebHost host) { IServiceScopeFactory scopeFactory = host.Services.GetService <IServiceScopeFactory>(); using (IServiceScope scope = scopeFactory.CreateScope()) { SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>(); seeder.Seed().Wait(); } }
private void Seed(IApplicationBuilder app) { using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var context = scope.ServiceProvider.GetService <IntellectDbContext>(); var userManager = scope.ServiceProvider.GetService <UserManager <ApplicationUser> >(); var roleManager = scope.ServiceProvider.GetService <RoleManager <IdentityRole> >(); context.Database.Migrate(); SeedDb.Seed(context, userManager, roleManager).Wait(); } }
protected void Application_Start(object sender, EventArgs e) { // Seed Database (Users, Categories, Blogs) SeedDb.Seed(); }