public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var env = services.GetRequiredService <IHostingEnvironment>(); var config = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables().Build(); ApplicationDbContext.CreateAdminAccount(services, config).Wait(); ApplicationDbContext.CreateAuthorRole(services).Wait(); if (bool.TryParse(config["UpdateSlugs"], out var update)) { if (update) { BlogDbContext.UpdateSlugs(services).Wait(); } } } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }