public static void Main(string[] args) { IWebHost host = BuildWebHost(args); // Try to seed the database if needed using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { Task articleSeeding = SeedArticles.Initialize(services); // Spinlock while the database is seeding while (!articleSeeding.IsCompleted) { } } catch { Console.Error.WriteLine("Could not seed the database with initial articles!"); throw; } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var logger = services.GetRequiredService <ILogger <Program> >(); try { SeedAdministrator.Seed(services).Wait(); SeedArticles.Seed(services); var context = services.GetRequiredService <ApplicationDbContext>(); } catch (Exception ex) { logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }