public static async Task InitializeAsync(ApplicationContext db, IAuthService authService) { await RoleInitialize.InitializeAsync(authService); await UserInitialize.InitializeAsync(authService); await StatusInitialize.InitializeAsync(db); await RegionInitialize.InitializeAsync(db); await ThemeCompanyInitialize.InitializeAsync(db, authService); }
//public static void Main(string[] args) //{ // CreateWebHostBuilder(args).Build().Run(); //} //Используется для создания ролей и пользователя с ролями public static async Task Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); await RoleInitialize.InitializeAsync(userManager, rolesManager); } 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 = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); context.Database.Migrate(); SeedData.Initialize(services); RoleInitialize.CreateRoles(services).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }