Exemple #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMemoryCache memoryCache)
        {
            DemoWeb.IocManager  = app.ApplicationServices.GetService <IIocManager>();
            DemoWeb.Environment = env;
            try//注意这里在本地开发允许时会重置数据库,并清空所有数据,如不需要请注释   在不存在数据库的时候请将这个地方的注释打开
            {
                if (env.IsDevelopment())
                {
                    using (var servicescope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>()
                                              .CreateScope())
                    {
                        //var dbcontent = servicescope.serviceprovider.getservice<demodbcontext>();
                        //checkmigrations(dbcontent);
                        var database = servicescope.ServiceProvider.GetService <DemoDbContext>().Database;
                        database.EnsureDeleted();
                        database.EnsureCreated();
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Logger.Error(ex, "Failed to migrate or seed database");
            }
            DemoWeb.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());
            DemoWeb.MemoryCache = memoryCache;
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials());//允许跨域
            app.UseHttpsRedirection();

            // Fetch errorInternal Server Error v1/swagger.json 错误  有方法未指明请求方式  GET POST
            #region Swagger

            app.UseSwagger(c => { c.RouteTemplate = "apidoc/{documentName}/swagger.json"; });
            app.UseSwaggerUI(c =>
            {
                c.RoutePrefix = "apidoc";
                c.SwaggerEndpoint("v1/swagger.json", "ContentCenter API V1");
                c.DocExpansion(DocExpansion.None);//默认文档展开方式
            });

            #endregion

            app.UseMvc(routes => { routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); });
            //app.UseMvc();
        }
Exemple #2
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMemoryCache memoryCache)
 {
     DemoWeb.IocManager  = app.ApplicationServices.GetService <IIocManager>();
     DemoWeb.Environment = env;
     try//注意这里在本地开发允许时会重置数据库,并清空所有数据,如不需要请注释   在不存在数据库的时候请将这个地方的注释打开
     {
         if (env.IsDevelopment())
         {
             using (var servicescope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>()
                                       .CreateScope())
             {
                 //var dbcontent = servicescope.serviceprovider.getservice<demodbcontext>();
                 //checkmigrations(dbcontent);
                 var database = servicescope.ServiceProvider.GetService <DemoDbContext>().Database;
                 database.EnsureDeleted();
                 database.EnsureCreated();
             }
         }
     }
     catch (Exception ex)
     {
         LogHelper.Logger.Error(ex, "Failed to migrate or seed database");
     }
     DemoWeb.Configure(app.ApplicationServices.GetRequiredService <IHttpContextAccessor>());
     DemoWeb.MemoryCache = memoryCache;
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     else
     {
         app.UseHsts();
     }
     app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().AllowCredentials());//允许跨域
     app.UseHttpsRedirection();
     app.UseMvc(routes => { routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}"); });
     //app.UseMvc();
 }