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();
        }
예제 #2
0
        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();
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
        }