public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var userManager = services.GetRequiredService <UserManager <AppUser> >(); var rolesManager = services.GetRequiredService <RoleManager <AppRole> >(); await UserInitializer.InitializeAsync(userManager, rolesManager); } host.Run(); }
private static async Task InitializeUsers(IWebHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <IdentityUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await UserInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService<UserManager<IdentityUser>>(); var rolesManager = services.GetRequiredService<RoleManager<IdentityRole>>(); await UserInitializer.InitializeAsync(userManager, rolesManager); } catch (Exception ex) { var logger = services.GetRequiredService<ILogger<Program>>(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }