// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { IConfigurationSection configSection = Configuration.GetSection("ServiceConfig"); ServiceConfigInfo.Init(configSection["consul"], configSection["configKey"], configSection["ip"], Convert.ToInt32(configSection["httpPort"])); services.AddGalaxyAuth("ShopInfoManage"); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(options => { options.AddPolicy("any", builder => { builder .WithOrigins("*") .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); services.Configure <MvcOptions>(options => { options.Filters.Add(new CorsAuthorizationFilterFactory("any")); }); new AutoMapperInit().Init(); DBConnectionProvider.Config(ServiceConfigInfo.Single.DBConfig.Server, ServiceConfigInfo.Single.DBConfig.Port, ServiceConfigInfo.Single.DBConfig.DBName, ServiceConfigInfo.Single.DBConfig.User, ServiceConfigInfo.Single.DBConfig.Password); CSRedisInitHelper.Init(ServiceConfigInfo.Single.RedisConfig.Server, System.Convert.ToInt32(ServiceConfigInfo.Single.RedisConfig.Port)); //注册Swagger生成器,定义一个和多个Swagger 文档 services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "ShopInfoServiceAPI", Version = "v1" }); c.SwaggerDoc("v2", new Info { Title = "ShopInfoServiceAPI_2", Version = "v2" }); c.IncludeXmlComments(AppDomain.CurrentDomain.BaseDirectory + "/Galaxy.Taurus.ShopInfoAPI.xml"); }); DependencyRegister dependencyRegister = new DependencyRegister(); ApplicationContainer = dependencyRegister.RegisterWeb(services); return(new AutofacServiceProvider(ApplicationContainer));//第三方IOC接管 core内置DI容器 }