public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { try { var concreteRentACarContext = scope.ServiceProvider.GetService <RentACarDbContext>(); RentACarDbInitializer.Initialize(concreteRentACarContext); } catch (Exception ex) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while migrating or initializing the database."); } } host.Run(); }
public static void Initialize(RentACarDbContext context) { var initializer = new RentACarDbInitializer(); initializer.SeedEverything(context); }