public override void OnActionExecuting(ActionExecutingContext context) { var provider = ServiceExtension.Get <IActionDescriptorCollectionProvider>(); var desc1 = (context.ActionDescriptor as ControllerActionDescriptor); var desc2 = provider.ActionDescriptors.Items.Cast <ControllerActionDescriptor>() .Where(t => t.MethodInfo.GetCustomAttribute <ActionAttribute>() != null && t.DisplayName == desc1.DisplayName).FirstOrDefault(); var desc3 = desc2 ?? desc1; var action = desc3.MethodInfo.GetCustomAttribute <ActionAttribute>(); if (action != null) { var actions = ServiceExtension.Get <IPermissionService>(); if (actions != null && !actions.HasPermission(context, desc3.Id)) { return; } } if (desc3.ActionName == "Index" && desc3.ControllerName == "Home") { if (User.Identity.IsAuthenticated) { string path = HttpContext.Request.Query["from"]; if (string.IsNullOrEmpty(path)) { path = CookieUtil.GetCookie(Constants.LAST_LOGIN_PATH); } if (!string.IsNullOrEmpty(path) && path != "/") { context.Result = Redirect(path); } } } base.OnActionExecuting(context); }
protected PathUtil() { IHostingEnvironment val = ServiceExtension.Get <IHostingEnvironment>(); _HostingEnvironment = val; _WebPhysicalPath = val.WebRootPath; _ContentPhysicalPath = val.ContentRootPath; if (ServiceExtension.HttpContext == null) { _WebVirtualPath = "/"; _AbsoluteUrl = "/"; } else { HttpRequest val2 = ServiceExtension.HttpContext.Request; PathString pathBase = val2.PathBase; _WebVirtualPath = pathBase.Value; if (string.IsNullOrWhiteSpace(_WebVirtualPath)) { _WebVirtualPath = "/"; } string scheme = val2.Scheme; HostString host = val2.Host; string value = host.Value; pathBase = val2.PathBase; _AbsoluteUrl = $"{scheme}://{value}{pathBase.Value}/"; } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddRazorPages(); ServiceExtension.ConfigureDbContext(services, Configuration); ServiceExtension.ConfigureWrapper(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews() .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix) .AddRazorRuntimeCompilation(); //注入数据库操作 services.AddSqlSugar(Configuration, ServiceLifetime.Scoped); //注入sqlsugar ServiceExtension.RegisterAssembly(services, "Service"); //服务注入 ServiceExtension.RegisterAssembly(services, "Repository"); //仓库注入 services.AddHttpClientFactoryHelper(); //http请求工厂注入 GlobalVar.Author_url = Configuration.GetValue <string>("Author_url").ToString(); //获取权限认证api地址 //初始化创建表格 services.AddInitDataTable(); services.AddSwaggerGen(c => { // 添加文档信息 c.SwaggerDoc("Common", new OpenApiInfo { Title = "接口", Version = "Common" }); //分组显示 //c.SwaggerDoc("Dashboard", new OpenApiInfo { Title = "Dashboard数据源", Version = "Dashboard" }); //分组显示 var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径) var xmlPath = Path.Combine(basePath, "OvenMonitoring.xml"); c.IncludeXmlComments(xmlPath); //启用数据注解 c.EnableAnnotations(); }); }
public void ValidateTest() { var response = new TestResponse(); var e = new ExecutionResult(); e.Status = ExecuteStatus.Failed; e.ExecuteMessages.Add(new ExecutionMessage { Help = "Test Help", Text = "Test Fail", Id = 1, Type = ExecutionMessageType.Error }); response.ExecutionResult = e; try { ServiceExtension.Validate(response); } catch (ServiceValidationException ex) { Assert.IsNotNull(ex); Assert.IsFalse(string.IsNullOrEmpty(ex.Message)); Assert.AreEqual("Test Fail", ex.Message); Assert.IsNotNull(ex.Errors); return; } Assert.Fail(); }
public virtual IServiceProvider GetServices() { var services = new ServiceCollection(); services.AddSingleton <IConfiguration>(new ConfigurationBuilder().Build()); var Configuration = services.BuildServiceProvider().GetService <IConfiguration>(); services.AddOptions(); services.AddXsrf(); services.AddXss(); var config2 = ConfigUtil.GetJsonConfig(); var lo = config2["SqlSugar:ConnectionString"]; services.AddSqlSugarClient <SqlSugarClient>(config => { //Configuration["sql:mssql"] config.ConnectionString = lo; config.DbType = DbType.SqlServer; config.IsAutoCloseConnection = true; config.InitKeyType = InitKeyType.Attribute; }); services.AddHttpContextAccessor(); services.AddHtmlEncoder(); services.AddBr(); //br压缩 services.AddResponseCompression(); //添加压缩 services.AddMemoryCache(); services.AddNlog(); //添加Nlog services.AddLogging(); RegisterBase(services); ServiceExtension.RegisterAssembly(services, "Services"); ServiceExtension.RegisterAssembly(services, "Repository"); serviceDescriptors = services; return(services.BuildServiceProvider()); }
public void ToServiceFaultExceptionTest() { var vf = new FaultException(); ServiceValidationException actual = ServiceExtension.ToServiceValidationException(vf); Assert.IsNotNull(actual); Assert.IsTrue(actual.Errors.Count == 1); Assert.AreEqual("Employment.Web.Mvc.Infrastructure.Exceptions.ServiceValidationException: The creator of this fault did not specify a Reason.", actual.ToString()); }
public void ToServiceValidationExceptionTest1() { FaultException <ValidationFault> vf = new FaultException <ValidationFault>(new ValidationFault()); vf.Detail.Add(new ValidationDetail { Key = string.Empty, Message = "Message", Tag = "Tag" }); ServiceValidationException actual = ServiceExtension.ToServiceValidationException(vf); Assert.IsNotNull(actual); Assert.IsTrue(actual.Errors.Count == 1); Assert.IsTrue(actual.Errors.ContainsKey("0")); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSqlSugar(Configuration, ServiceLifetime.Scoped); //注入sqlsugar services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //注入Session工厂类接口 services.AddAuthentication(Configuration); ServiceExtension.RegisterAssembly(services, "Advantech.Service"); //服务注入 ServiceExtension.RegisterAssembly(services, "Advantech.Repository"); //仓库注入 services.AddThriftRpc(); //增加RPC访问 services.AddInitDataTable(); //初始化服务数据库表 }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //This is for AppMetrics, Prometheus and Grafana, it may not be required but in case it throws errors //this code is necessary. services.Configure <KestrelServerOptions>(options => { options.AllowSynchronousIO = true; }); services.AddMetrics(); var key = new byte[10]; //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); #region System-Services // Adding assemblies will read any profiles defined in a project. services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); #endregion services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddMicrosoftIdentityWebApi(Configuration); // Creating policies that wraps the authorization requirements services.AddAuthorization(); services.AddCors(o => o.AddPolicy("default", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); /* services.AddScoped<IConfigurationBuilder, ConfigurationBuilder>(); * services.AddAuthentication(x => * { * x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; * x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; * }) * .AddJwtBearer(x => * { * x.RequireHttpsMetadata = false; * x.SaveToken = true; * * }); * */ ServiceExtension.RegisterServices(services); }
public virtual IServiceProvider GetServices() { var services = new ServiceCollection(); services.AddSingleton <IConfiguration>(new ConfigurationBuilder().Build()); var Configuration = services.BuildServiceProvider().GetService <IConfiguration>(); services.AddJson(o => { o.JsonType = JsonType.Jil; }); services.AddDIProperty(); services.AddOptions(); services.AddXsrf(); services.AddXss(); var config2 = ConfigUtil.GetJsonConfig(); var sqlSugarConfig = SqlSugarConfig.GetConnectionString(config2); services.AddSqlSugarClient <SqlSugarClient>(config => { config.ConnectionString = sqlSugarConfig.Item2; config.DbType = sqlSugarConfig.Item1; config.IsAutoCloseConnection = true; config.InitKeyType = InitKeyType.Attribute; //config.IsShardSameThread = true; }); services.AddHttpContextAccessor(); services.AddHtmlEncoder(); services.AddBr(); //br压缩 services.AddResponseCompression(); //添加压缩 services.AddMemoryCache(); services.AddMediatR(typeof(BaseControllerTest).GetTypeInfo().Assembly); services.AddNlog(); //添加Nlog services.AddLogging(); RegisterBase(services); ServiceExtension.RegisterAssembly(services, "Services"); ServiceExtension.RegisterAssembly(services, "Repository"); serviceDescriptors = services; services.AddSingleton <IApplicationBuilder>(new ApplicationBuilder(services.BuildServiceProvider())); var app = services.BuildServiceProvider().GetService <IApplicationBuilder>(); app.UseGlobalCore(); return(services.BuildServiceProvider()); }
static WebBaseController() { try { var actions = ServiceExtension.Get <IPermissionService>(); if (actions != null) { var provider = ServiceExtension.Get <IActionDescriptorCollectionProvider>(); var descriptorList = provider.ActionDescriptors.Items.Cast <ControllerActionDescriptor>() .Where(t => t.MethodInfo.GetCustomAttribute <ActionAttribute>() != null).ToList(); actions.RegistAction(descriptorList); actions.RegistRole(); } } catch (System.Exception ex) { LogUtil <WebBaseController> .Error(ex.Message); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSwaggerGen(c => { // 添加文档信息 c.SwaggerDoc("JWT", new OpenApiInfo { Title = "JWT权限认证", Version = "JWT" }); //分组显示 c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "请输入带有Bearer的Token", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey //In = "header", //Type = "apiKey" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" } }, new string[] { } } }); var basePath = Path.GetDirectoryName(typeof(Program).Assembly.Location);//获取应用程序所在目录(绝对,不受工作目录影响,建议采用此方法获取路径) var xmlPath = Path.Combine(basePath, "Authorize.xml"); c.IncludeXmlComments(xmlPath); //启用数据注解 c.EnableAnnotations(); }); services.InjectAuthentication(Configuration); services.AddSqlSugar(Configuration, ServiceLifetime.Scoped); //注入sqlsugar ServiceExtension.RegisterAssembly(services, "Service"); //服务注入 ServiceExtension.RegisterAssembly(services, "Repository"); //仓库注入 services.AddScoped <IUserLoginService, UserLoginService>(); //用户登录接口对象注入 services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddControllersWithViews(); services.AddControllersWithViews().AddRazorRuntimeCompilation(); services.AddSingleton <AuthServerConfig>(ServiceProvider => new AuthServerConfig() { LoginUrl = "/Home/Index", //登录页面 TokenServerUrl = "http://172.21.168.5:8010" //授权服务地址 }); services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN"); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //注入Session工厂类接口 services.AddSqlSugar(Configuration, ServiceLifetime.Scoped); //注入sqlsugar ServiceExtension.RegisterAssembly(services, "Advantech.Service"); //服务注入 ServiceExtension.RegisterAssembly(services, "Advantech.Repository"); //仓库注入 services.AddTransient <IHttpRequest, HttpRequestHelper>(); services.AddSession(); //测试使用 services.AddHttpClientFactoryHelper(); //http请求工厂注入 services.AddInitDataTable(); //初始化服务数据库表 //services.AddSingleton<UserAuthorizeAttribute>();//注入用户权限过滤器 }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var serviceList = _appSettings.ServiceNameList ?? new string[] { }; while (!stoppingToken.IsCancellationRequested) { var service = new ServiceExtension(); var scs = service.GetServices(serviceList); if (scs.Count > 0) { foreach (var sc in scs) { if (sc.Status == ServiceControllerStatus.Stopped) { sc.Start(); while (sc.Status == ServiceControllerStatus.Stopped) { Thread.Sleep(1000); _logger.LogInformation($"Worker Start {sc.DisplayName} at: {DateTimeOffset.Now}"); sc.Refresh(); } } if (sc.Status == ServiceControllerStatus.Paused) { sc.Start(); while (sc.Status == ServiceControllerStatus.Paused) { Thread.Sleep(1000); _logger.LogInformation($"Worker Start {sc.DisplayName} at: {DateTimeOffset.Now}"); sc.Refresh(); } } } } // _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); await Task.Delay(60000, stoppingToken); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //注入Session工厂类接口 services.AddSqlSugar(Configuration, ServiceLifetime.Scoped); //注入sqlsugar ServiceExtension.RegisterAssembly(services, "Advantech.Service"); //服务注入 ServiceExtension.RegisterAssembly(services, "Advantech.Repository"); //仓库注入 services.AddInitDataTable(); //初始化服务数据库表 services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins("*"); builder.AllowAnyHeader(); //允许任意头 builder.AllowAnyMethod(); //允许任意方法 }); }); services.AddControllersWithViews(o => { o.UseGeneralRoutePrefix("program"); });//默认路由前缀 }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // 注册Swagger服务 services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "File service", Version = "v1" }); }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //注入Session工厂类接口 services.AddSqlSugar(Configuration, ServiceLifetime.Scoped); //注入sqlsugar ServiceExtension.RegisterAssembly(services, "Advantech.Service"); //服务注入 ServiceExtension.RegisterAssembly(services, "Advantech.Repository"); //仓库注入 services.AddInitDataTable(); //初始化服务数据库表 services.AddCors(options => { options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins("*"); builder.AllowAnyHeader(); //允许任意头 builder.AllowAnyMethod(); //允许任意方法 }); }); services.AddHttpClientFactoryHelper();//http请求工厂注入 services.AddSingleton <AuthServerConfig>(ServiceProvider => new AuthServerConfig() { LoginUrl = "/Home/Index", //登录页面 TokenServerUrl = "http://172.21.168.5:8080" //授权服务地址,不带后缀斜杠 }); services.AddScoped <UserAuthorize>(); //注入用户权限过滤器 services.AddSession(); //权限需要使用 services.AddControllersWithViews(o => { o.UseGeneralRoutePrefix("file"); }); //默认路由前缀 }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); // 注册Swagger服务 services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Security service", Version = "v1" }); }); services.AddSqlSugar(Configuration, ServiceLifetime.Scoped); //注入sqlsugar services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //注入Session工厂类接口 services.AddAuthentication(Configuration); ServiceExtension.RegisterAssembly(services, "Advantech.Service"); //服务注入 ServiceExtension.RegisterAssembly(services, "Advantech.Repository"); //仓库注入 services.AddScoped <IUserLoginService, UserLoginService>(); //用户登录接口对象注入 services.AddThriftRpc(); //增加RPC访问 services.AddInitDataTable(); //初始化服务数据库表 services.AddControllersWithViews(o => { o.UseGeneralRoutePrefix("Security"); }); //默认路由前缀 }
//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); }
//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); }
//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(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ServiceExtension.AddServicesInAssembly(services, Configuration); }