Exemple #1
0
        /// <summary>
        /// 管理服务容器
        /// </summary>
        /// <param name="services"></param>
        public void ConfigureServices(IServiceCollection services)
        {
            // IISOptions
            services.Configure <IISOptions>(opt =>
            {
            });

            // 数据库
            services.AddDbContext <ValuesContext>(opt =>
            {
                opt.UseInMemoryDatabase("Values");
            });
            services.AddDbContextOfSqlSugar <ValuesContextOfSqlSugar>(opt =>
            {
                opt.IsAutoCloseConnection = true;
                opt.DbType           = SqlSugar.DbType.SqlServer;
                opt.ConnectionString = Configuration.GetConnectionString("DefaultConnection");
            });

            // Mvc
            services.AddMvc();//.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            // 缓存
            ECachingContainer.ConfigureServices(services);
            // api认证
            ApiAuthorized.ConfigureServices(services);
            ApiAuthorized.ConfigAppAsync(() =>
            {
                return(new List <IAppInfo>
                {
                    new AppInfo()
                    {
                        appid = "FA9F0K19",
                        name = "ApiAuth1",
                        secret = "IFHA89IE"
                    }
                });
            });
        }
Exemple #2
0
        /// <summary>
        /// Http处理Pipeline中间件Middleware
        /// </summary>
        /// <param name="app"></param>
        /// <param name="env"></param>
        /// <param name="loggerFactory"></param>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            // 日志
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            // 环境
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            // 启用静态资源访问
            app.UseStaticFiles();
            // 导航到 http://localhost:<port>/swagger 查看 Swagger UI
            // 导航到 http://localhost:<port>/swagger/v1/swagger.json 查看 Swagger 规范
            NSwagContainer.Configure(app, env);

            // 缓存
            ECachingContainer.Configure(app, env);

            // 认证
            ApiAuthorized.Configure(app, env, loggerFactory);

            // 启用Https
            if ("true" == Configuration["Https"])
            {
                app.UseHttpsRedirection();
            }

            // Mvc
            app.UseMvc();
        }