Exemple #1
0
        //IServiceProvider This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(option =>
            {
                option.Filters.Add <BaseExceptionAttribute>();
                //option.Filters.Add<FilterXSSAttribute>();
                option.Conventions.Add(new ApplicationDescription("title", Configuration["sys:title"]));
                option.Conventions.Add(new ApplicationDescription("company", Configuration["sys:company"]));
                option.Conventions.Add(new ApplicationDescription("customer", Configuration["sys:customer"]));
            }).SetCompatibilityVersion(CompatibilityVersion.Latest);
            //services.Configure<CookiePolicyOptions>(options =>
            //{
            //    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            //    options.CheckConsentNeeded = context => true;
            //    options.MinimumSameSitePolicy = SameSiteMode.None;
            //});
            services.AddTimedJob();
            services.AddOptions();
            services.AddXsrf();
            services.AddXss();
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, cfg =>
            {
                cfg.LoginPath         = "/Login/Index";
                cfg.ExpireTimeSpan    = TimeSpan.FromDays(1);
                cfg.Cookie.Expiration = TimeSpan.FromDays(1);
                cfg.Cookie.Name       = CookieAuthenticationDefaults.AuthenticationScheme;
                cfg.Cookie.Path       = "/";
                cfg.Cookie.HttpOnly   = true;
                cfg.SlidingExpiration = true;
            });
            var sqlSugarConfig = SqlSugarConfig.GetConnectionString(Configuration);

            services.AddSqlSugarClient <SqlSugarClient>(config =>
            {
                config.ConnectionString      = sqlSugarConfig.Item2;
                config.DbType                = sqlSugarConfig.Item1;
                config.IsAutoCloseConnection = true;
                config.InitKeyType           = InitKeyType.Attribute;
                //config.IsShardSameThread = true;
            });
            services.AddJson(o =>
            {
                o.JsonType = JsonType.Jil;
            });
            services.AddHttpContextAccessor();
            services.AddHtmlEncoder();
            //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            services.AddBr();                  //br压缩
            services.AddResponseCompression(); //添加压缩
            services.AddResponseCaching();     //响应式缓存
            services.AddMemoryCache();

            //@1 DependencyInjection 注册
            services.AddNlog(); //添加Nlog
            RegisterBase(services);
            ServiceExtension.RegisterAssembly(services, "Services");
            ServiceExtension.RegisterAssembly(services, "Repository");
            var bulid = services.BuildServiceProvider();

            ServiceResolve.SetServiceResolve(bulid);
        }
Exemple #2
0
        //IServiceProvider This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(option =>
            {
                option.Filters.Add <BaseExceptionAttribute>();
                //option.Filters.Add<FilterXSSAttribute>();
                option.Conventions.Add(new ApplicationDescription("keywords", Configuration["sys:keywords"]));
                option.Conventions.Add(new ApplicationDescription("description", Configuration["sys:description"]));
                option.Conventions.Add(new ApplicationDescription("company", Configuration["sys:company"]));
                option.Conventions.Add(new ApplicationDescription("customer", Configuration["sys:customer"]));
            }).SetCompatibilityVersion(CompatibilityVersion.Latest);
            //services.Configure<CookiePolicyOptions>(options =>
            //{
            //    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            //    options.CheckConsentNeeded = context => true;
            //    options.MinimumSameSitePolicy = SameSiteMode.None;
            //});
            services.AddTimedJob();
            services.AddOptions();
            services.AddXsrf();
            services.AddXss();
            services.AddAuthentication(c =>
            {
                c.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                c.DefaultChallengeScheme    = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie(cfg =>
            {
                cfg.LoginPath  = "/Login/Index";
                cfg.LogoutPath = "/Login/Logout";
                //cfg.ExpireTimeSpan = TimeSpan.FromDays(1);
                //cfg.Cookie.Expiration = TimeSpan.FromDays(1);
                cfg.Cookie.Name     = CookieAuthenticationDefaults.AuthenticationScheme;
                cfg.Cookie.Path     = "/";
                cfg.Cookie.HttpOnly = true;
                //cfg.SlidingExpiration = true;
            });
            var sqlSugarConfig = SqlSugarConfig.GetConnectionString(Configuration);

            services.AddSqlSugarClient <SqlSugarClient>(config =>
            {
                config.ConnectionString      = sqlSugarConfig.Item2;
                config.DbType                = sqlSugarConfig.Item1;
                config.IsAutoCloseConnection = true;
                config.InitKeyType           = InitKeyType.Attribute;
                //config.IsShardSameThread = true;
            });
            services.AddJson(o =>
            {
                o.JsonType = JsonType.Jil;
            });
            //services.AddDIProperty();
            services.AddHttpContextAccessor();
            services.AddHtmlEncoder();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            services.AddBr();                  //br压缩
            services.AddResponseCompression(); //添加压缩
            services.AddResponseCaching();     //响应式缓存
            services.AddMemoryCache();
            services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
            //@1 DependencyInjection 注册
            services.AddNlog(); //添加Nlog
            RegisterBase(services);
            //services.AddScoped(provider =>
            //{
            //    Func<string, SqlSugarClient> func = key =>
            //    {
            //        switch (key)
            //        {
            //            case "1":
            //                return new SqlSugarClient(new ConnectionConfig()
            //                {
            //                    ConfigId = "111",
            //                    ConnectionString = sqlSugarConfig.Item2,
            //                    DbType = sqlSugarConfig.Item1,
            //                    IsAutoCloseConnection = true,
            //                    InitKeyType = InitKeyType.Attribute,
            //                });

            //            case "2":
            //                return new SqlSugarClient(new ConnectionConfig()
            //                {
            //                    ConfigId = "222",
            //                    ConnectionString = sqlSugarConfig.Item2,
            //                    DbType = sqlSugarConfig.Item1,
            //                    IsAutoCloseConnection = true,
            //                    InitKeyType = InitKeyType.Attribute,
            //                });

            //            default:
            //                throw new NotSupportedException($"Not Support key : {key}");
            //        }
            //    };
            //    return func;
            //});
            ServiceExtension.RegisterAssembly(services, "Services");
            ServiceExtension.RegisterAssembly(services, "Repository");
            var bulid = services.BuildServiceProvider();

            ServiceResolve.SetServiceResolve(bulid);
        }
Exemple #3
0
        //IServiceProvider This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            WCSApiAccessor.Host         = Configuration["Host:WCS"];
            MESApiAccessor.Host         = Configuration["Host:MES"];
            WMSBaseApiAccessor.WMSProxy = Configuration["Host:WMSPROXY"];

            services.AddMvc(option =>
            {
                option.Filters.Add <BaseExceptionAttribute>();
                //option.Filters.Add<FilterXSSAttribute>();
                option.Conventions.Add(new ApplicationDescription("title", Configuration["sys:title"]));
                option.Conventions.Add(new ApplicationDescription("company", Configuration["sys:company"]));
                option.Conventions.Add(new ApplicationDescription("customer", Configuration["sys:customer"]));
            }).SetCompatibilityVersion(CompatibilityVersion.Latest);
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "API", Version = "v1"
                });
            });
            //services.Configure<CookiePolicyOptions>(options =>
            //{
            //    // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            //    options.CheckConsentNeeded = context => true;
            //    options.MinimumSameSitePolicy = SameSiteMode.None;
            //});
            services.AddTimedJob();
            services.AddOptions();
            services.AddXsrf();
            services.AddXss();
            services.AddAuthentication(c =>
            {
                c.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                c.DefaultChallengeScheme    = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie(cfg =>
            {
                cfg.LoginPath  = "/Login/Index";
                cfg.LogoutPath = "/Login/Logout";
                //cfg.ExpireTimeSpan = TimeSpan.FromDays(1);
                //cfg.Cookie.Expiration = TimeSpan.FromDays(1);
                cfg.Cookie.Name     = CookieAuthenticationDefaults.AuthenticationScheme;
                cfg.Cookie.Path     = "/";
                cfg.Cookie.HttpOnly = true;
                //cfg.SlidingExpiration = true;
            });
            var sqlSugarConfig = SqlSugarConfig.GetConnectionString(Configuration);

            services.AddSqlSugarClient <SqlSugarClient>(config =>
            {
                config.ConnectionString      = sqlSugarConfig.Item2;
                config.DbType                = sqlSugarConfig.Item1;
                config.IsAutoCloseConnection = true;
                config.InitKeyType           = InitKeyType.Attribute;
                //config.IsShardSameThread = false;
            });
            services.AddJson(o =>
            {
                o.JsonType = JsonType.Jil;
            });
            services.AddSoapCore();
            services.AddDIProperty();
            services.AddHttpContextAccessor();
            services.AddHtmlEncoder();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            services.AddBr();                  //br压缩
            services.AddResponseCompression(); //添加压缩
            services.AddResponseCaching();     //响应式缓存
            services.AddMemoryCache();
            services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
            //@1 DependencyInjection 注册
            services.AddNlog(); //添加Nlog
            RegisterBase(services);
            ServiceExtension.RegisterAssembly(services, "Services");
            ServiceExtension.RegisterAssembly(services, "Repository");
            var bulid = services.BuildServiceProvider();

            ServiceResolve.SetServiceResolve(bulid);



            SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
            {
                DbType                = sqlSugarConfig.Item1,
                ConnectionString      = sqlSugarConfig.Item2,
                InitKeyType           = InitKeyType.Attribute,
                IsAutoCloseConnection = true,
            });

            //OutputDataBase(db);
            InitDataBase(db);
            InitSystemData(db);
            db.Close();
        }