public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()){ var services = scope.ServiceProvider; var context = services.GetRequiredService <TodoContext>(); TodoContextSeed seed = new TodoContextSeed(); seed.SeedAsync(context).GetAwaiter(); } host.Run(); }
public InMemoryDbContextFixture() { var options = new DbContextOptionsBuilder <TodoContext>() .UseInMemoryDatabase("IntellectualProperty") .ConfigureWarnings(x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)) .Options; _context = new TodoContext(options); _context.Database.EnsureCreated(); TodoContextSeed data = new TodoContextSeed(); data.SeedAsync(_context).GetAwaiter(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { var todoContext = services.GetRequiredService <TodoContext>(); TodoContextSeed.SeedAsync(todoContext, loggerFactory, 5).Wait(); } catch (Exception ex) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError(ex, "Error occurred"); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { TodoContextSeed.SeedAsync(services) .Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }