Beispiel #1
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services   = scope.ServiceProvider;
                var dbQuantity = services.GetRequiredService <AirportDbContext>();
                AirportsDbInitializer.Initialize(dbQuantity);
                StopOversDbInitializer.Initialize(dbQuantity);
                AirlineCompaniesDbInitializer.Initialize(dbQuantity);
                DimensionsDbInitializer.Initialize(dbQuantity);
            }
            GetRepository.SetServiceProvider(host.Services);
            host.Run();
        }
Beispiel #2
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureServices(s => {
                removeCurrentDb <ApplicationDbContext>(s);
                removeCurrentDb <StoreDbContext>(s);

                s.AddEntityFrameworkInMemoryDatabase();

                addInMemoryDb <ApplicationDbContext>(s);
                addInMemoryDb <StoreDbContext>(s);



                var sp = s.BuildServiceProvider();

                using (var scope = sp.CreateScope()) {
                    var scopedServices = scope.ServiceProvider;
                    ensureDbsAreCreated(scopedServices, dbContexts);
                }

                GetRepository.SetServiceProvider(sp);
            });
        }