public static void Main(string[] args)
        {
            //CreateHostBuilder(args).Build().Run();

            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                var context  = services.GetRequiredService <PMContext>();

                PMContext.Initialize(services);
            }
            host.Run();
        }
Beispiel #2
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder.ConfigureServices(services =>
            {
                var serviceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider();

                services.AddDbContext <PMContext>(options =>
                {
                    options.UseInMemoryDatabase("ProjectManagementTestData");
                });

                var objBSP = services.BuildServiceProvider();

                using (var scope = objBSP.CreateScope())
                {
                    var scopedServices = scope.ServiceProvider;
                    var db             = scopedServices.GetRequiredService <PMContext>();
                    db.Database.EnsureCreated();
                    PMContext.Initialize(scopedServices);
                }
            });
        }