public async static Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); var context = services.GetRequiredService <ApplicationDbContext>(); if (context.Database.IsSqlServer()) { context.Database.Migrate(); } var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var placesService = services.GetRequiredService <IPlacesService>(); var meshesService = services.GetRequiredService <IMeshesService>(); await ApplicationDbContextSeed.SeedDefaultUserAsync(userManager, roleManager); await ApplicationDbContextSeed.SeedDefaultPlacesAsync(context, placesService, meshesService, logger); } catch (Exception ex) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while migrating or seeding the database."); throw; } } await host.RunAsync(); }