/// <summary> /// 配置服务 /// </summary> /// <param name="services"></param> public IServiceProvider ConfigureServices(IServiceCollection services) { ApplicationData.Services = services; services.AddWebAPIServices(); services.AddResponseCompression(); #region 帮助文档 /*Swashbuckle.AspNetCore*/ services.AddSwaggerGen(m => { m.SwaggerDoc(_baseConfigure.AppName, new Info { Version = "0.1", Title = _baseConfigure.AppName, Description = "提供WebAPI接口", TermsOfService = "None", Contact = new Contact { Name = "Materal", Email = "*****@*****.**", Url = "" } }); foreach (string path in _baseConfigure.SwaggerHelperXmlPathArray) { m.IncludeXmlComments(path); } }); #endregion #region 跨域 services.AddCors(options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader())); #endregion #region 配置MVC services.AddMvc(options => options.Filters.Add <ExceptionProcessFilter>()) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .AddJsonOptions(options => { options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; options.SerializerSettings.ContractResolver = new DefaultContractResolver(); }); #endregion ApplicationData.Build(); return(ApplicationData.ServiceProvider); }