示例#1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, ProductsDbContext productsDbContext)
        {
            if (HostingEnvironment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMvc();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            using (var serviceScope = app
                                      .ApplicationServices
                                      .GetService <IServiceScopeFactory>()
                                      .CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService <ProductsDbContext>();
                context.Database.EnsureCreated();
            }

            productsDbContext.Seed();
        }