예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PaginationDemo v1"));

                //initialize data seeds
                using var serviceScope = app.ApplicationServices
                                         .GetRequiredService <IServiceScopeFactory>()
                                         .CreateScope();

                var service = serviceScope.ServiceProvider;

                FakeDataSeeder.Seed(service);
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ItemContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                // initialize data seeds
                using var serviceScope = app.ApplicationServices
                                         .GetRequiredService <IServiceScopeFactory>()
                                         .CreateScope();
                var service = serviceScope.ServiceProvider;

                FakeDataSeeder.Seed(service);
            }

            db.Database.EnsureCreated();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                using var serviceScope = app.ApplicationServices
                                         .GetRequiredService <IServiceScopeFactory>()
                                         .CreateScope();

                var service = serviceScope.ServiceProvider;

                FakeDataSeeder.Seed(service);

                app.UseDeveloperExceptionPage();
            }
            app.UseDefaultFiles();
            app.UseStaticFiles();
            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        //https://exceptionnotfound.net/ef-core-inmemory-asp-net-core-store-database/
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            var config = host.Services.GetRequiredService <IConfiguration>();

            bool isDataFake = bool.Parse(config["IsDataFake"]);

            if (isDataFake)
            {
                //1. Find the service layer within our scope.
                using (var scope = host.Services.CreateScope())
                {
                    //2. Get the instance of BoardGamesDBContext in our services layer
                    var services = scope.ServiceProvider;

                    var context   = services.GetRequiredService <ApplicationDbContext>();
                    var generator = services.GetRequiredService <FakeDataGenerator>();

                    //3. Call the DataGenerator to create sample data
                    FakeDataSeeder.Initialize(context, generator);
                }
            }

            //Continue to run the application
            host.Run();
        }