public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try{ var context = services.GetRequiredService <DataContext>(); var userManager = services.GetRequiredService <UserManager <AppUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); context.Database.Migrate(); //verifica daca exista baza de date, daca nu, o creeaza Seed2.SeedData(context, userManager, roleManager).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured during migration"); } host.Run(); } }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { Seed1.Initialize(services); Seed2.Initialize(services); Seed3.Initialize(services); Seed4.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }