protected SolarSystemDbContext GetContextWithData() { var options = new DbContextOptionsBuilder <SolarSystemDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new SolarSystemDbContext(options); context.Database.EnsureCreated(); SolarSystemInitialiser.Initialise(context); return(context); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { try { var context = scope.ServiceProvider.GetService <SolarSystemDbContext>(); context?.Database.Migrate(); SolarSystemInitialiser.Initialise(context); } catch (Exception ex) { var logger = scope.ServiceProvider.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while migrating or initializing the database."); } } host.Run(); }