public static void EnsureSeeded(this BoilerplateContext context) { RolesSeed.Seed(context); context.SaveChanges(); UserSeed.Seed(context); context.SaveChanges(); }
private static async Task SeedIdentity(IHost host) { using var serviceScope = host.Services.CreateScope(); var roleManager = serviceScope.ServiceProvider .GetRequiredService <RoleManager <IdentityRole> >(); var userManager = serviceScope.ServiceProvider .GetRequiredService <UserManager <IdentityUser> >(); await RolesSeed.Seed(roleManager); await UsersSeed.Seed(userManager); }
// 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(); app.UseBrowserLink(); //} //else //{ // app.UseExceptionHandler("/Home/Error"); //} app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); IServiceScopeFactory scopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>(); using (IServiceScope scope = scopeFactory.CreateScope()) { var profilesRepository = scope.ServiceProvider.GetRequiredService <IProfilesRepository>(); ProfilesSeed.Seed(profilesRepository); var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var usersSeed = new UsersSeed(profilesRepository); usersSeed.Seed(userManager).Wait(); RolesSeed.Seed(roleManager).Wait(); UserRolesSeed.Seed(userManager).Wait(); } }
private void SeedData(UserManager <AppUser> userManager, RoleManager <IdentityRole> roleManager) { RolesSeed.Seed(roleManager); SeedUsers(userManager); }