public async static Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); if (context.Database.IsSqlServer()) { context.Database.Migrate(); } await ApplicationDbContextSeed.SeedCategoriesAsync(context); } catch (System.Exception ex) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured during migration or seeding."); throw; } await host.RunAsync(); } //CreateHostBuilder(args).Build().Run(); }