/// <summary> /// Configure方法是asp.net core程序用来具体指定如何处理每个http请求的, /// 例如我们可以让这个程序知道我使用mvc来处理http请求, /// 那就调用app.UseMvc()这个方法就行. 但是目前, 所有的http请求都会导致返回"Hello World!" /// </summary> /// <param name="app"></param> /// <param name="env"></param> /// <param name="loggerFactory"></param> /// <param name="productContext"></param> /// <param name="myContext"></param> // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, ProductContext productContext) { loggerFactory.AddNLog(); loggerFactory.AddDebug();//填写日志 if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(); } //使用日志服务 // loggerFactory.AddProvider(new NLogLoggerProvider()); //跨域使用 app.UseCors(builder => { builder.AllowAnyMethod(); builder.AllowAnyHeader(); builder.AllowAnyOrigin(); }); // app.UseCors("AllowAllOrign"); //status code middleware 提供显示错误信息时的友好界面显示格式 app.UseStatusCodePages(); productContext.EnsureSeedDataForContext(); // myContext.EnsureSeedDataForContext(); //数据访问初始化 //sweagger服务添加 app.UseMvcWithDefaultRoute(); //注册AutoMapper AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <Product, ProductWithoutMaterialDto>(); cfg.CreateMap <Product, ProductDot>(); cfg.CreateMap <Material, MaterialDto>(); cfg.CreateMap <Product, ProductCreation>(); cfg.CreateMap <ProductCreation, ProductCreation>(); cfg.CreateMap <ProductCreation, Product>(); cfg.CreateMap <ProductModification, Product>(); cfg.CreateMap <Product, ProductModification>(); cfg.CreateMap <BuyerDto, Buyer>(); cfg.CreateMap <Buyer, BuyerDto>(); cfg.CreateMap <Buyer, BuyerCreation>(); cfg.CreateMap <BuyerCreation, Buyer>(); cfg.CreateMap <Indent, IndentDto>(); cfg.CreateMap <IndentDto, Indent>(); cfg.CreateMap <Indent, Indent>(); }); app.UseSwagger(c => { }); app.UseSwaggerUI(c => { c.ShowExtensions(); c.ValidatorUrl(null); c.SwaggerEndpoint("/swagger/v1/swagger.json", "测试服务器 V1"); }); app.UseAuthentication();//添加验证中间件 app.UseMvc(); }