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 <BlogContext>(); context.Database.Migrate(); Seed.SeedCategories(context); Seed.SeedArticles(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured during migration"); } } host.Run(); }