Пример #1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
					NekoPetShopContext context = scope.ServiceProvider.GetService<NekoPetShopContext>();
					IDBInitializer dbInitializer = scope.ServiceProvider.GetService<IDBInitializer>();
					dbInitializer.Seed(context);
                }
                app.UseDeveloperExceptionPage();
            }
            else
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
					NekoPetShopContext context = scope.ServiceProvider.GetService<NekoPetShopContext>();
					IDBInitializer dbInitializer = scope.ServiceProvider.GetService<IDBInitializer>();
					dbInitializer.Seed(context);
				}
                app.UseDeveloperExceptionPage();
                app.UseHsts();
            }

			app.UseCors(builder =>
			{
				builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader();
			});

			app.UseHttpsRedirection();
			app.UseAuthentication();
			app.UseMvc();
        }
Пример #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)
        {
            if (env.IsDevelopment())
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    PetShop2020DBContext context = scope.ServiceProvider.GetService <PetShop2020DBContext>();
                    context.Database.EnsureDeleted(); // only in dev mode. never in prod mode or the whole database will be lost.
                    context.Database.EnsureCreated();
                    IDBInitializer DbInit = scope.ServiceProvider.GetService <IDBInitializer>();
                    DbInit.Seed(context);
                }

                app.UseDeveloperExceptionPage();
            }
            if (env.IsProduction())
            {
                using (var scope = app.ApplicationServices.CreateScope())
                {
                    PetShop2020DBContext context = scope.ServiceProvider.GetService <PetShop2020DBContext>();
                    context.Database.EnsureCreated();
                    IDBInitializer dbInitializer = scope.ServiceProvider.GetService <IDBInitializer>();
                    dbInitializer.Seed(context);
                }
            }
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Pet Shop API");
                options.RoutePrefix = "";
            });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors();

            app.UseAuthentication();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>

                             { endpoints.MapControllers(); });
        }