From 9f5b8e985807732112304bc968f2523f7e54b701 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Mon, 5 Aug 2024 10:41:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=8E=8B=E7=BC=A9=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8E=8B=E7=BC=A9=E7=BA=A7=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRC.Core.SCP/HostConfig/EFSetup.cs | 2 +- .../ResponseCompressionSetup.cs | 14 ++++++- .../Context/IRaCISDBContext.cs | 40 ++++++++++--------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/IRC.Core.SCP/HostConfig/EFSetup.cs b/IRC.Core.SCP/HostConfig/EFSetup.cs index 921f293b9..00ee49222 100644 --- a/IRC.Core.SCP/HostConfig/EFSetup.cs +++ b/IRC.Core.SCP/HostConfig/EFSetup.cs @@ -19,7 +19,7 @@ namespace IRaCIS.Core.SCP //这个注入没有成功--注入是没问题的,构造函数也只是支持参数就好,错在注入的地方不能写DbContext //Web程序中通过重用池中DbContext实例可提高高并发场景下的吞吐量, 这在概念上类似于ADO.NET Provider原生的连接池操作方式,具有节省DbContext实例化成本的优点 - services.AddDbContext(options => + services.AddDbContextPool(options => { // 在控制台 //public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => { builder.AddConsole(); }); diff --git a/IRaCIS.Core.API/_ServiceExtensions/ResponseCompressionSetup.cs b/IRaCIS.Core.API/_ServiceExtensions/ResponseCompressionSetup.cs index 6037273da..5bc11b6cb 100644 --- a/IRaCIS.Core.API/_ServiceExtensions/ResponseCompressionSetup.cs +++ b/IRaCIS.Core.API/_ServiceExtensions/ResponseCompressionSetup.cs @@ -1,18 +1,30 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.ResponseCompression; using Microsoft.Extensions.DependencyInjection; +using System.IO.Compression; namespace IRaCIS.Core.API { - public static class ResponseCompressionSetup + public static class ResponseCompressionSetup { public static void AddResponseCompressionSetup(this IServiceCollection services) { services.AddResponseCompression(options => { + options.EnableForHttps = true; options.Providers.Add(); options.Providers.Add(); }); + + services.Configure(options => + { + options.Level = CompressionLevel.Optimal; + }); + + services.Configure(options => + { + options.Level = CompressionLevel.Optimal; + }); } } } diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 210224194..44a2ad291 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -24,32 +24,34 @@ using IRaCIS.Core.Infrastructure; namespace IRaCIS.Core.Infra.EFCore { + /// + /// 报错,添加subject 报错,重复添加访视 + /// + //public class IRaCISDBScopedFactory : IDbContextFactory + //{ - public class IRaCISDBScopedFactory : IDbContextFactory - { + // private readonly IDbContextFactory _pooledFactory; + // private readonly IUserInfo _userInfo; - private readonly IDbContextFactory _pooledFactory; - private readonly IUserInfo _userInfo; + // public IRaCISDBScopedFactory(IDbContextFactory pooledFactory,IUserInfo userInfo) + // { + // _pooledFactory = pooledFactory; + // _userInfo = userInfo; + // } - public IRaCISDBScopedFactory(IDbContextFactory pooledFactory,IUserInfo userInfo) - { - _pooledFactory = pooledFactory; - _userInfo = userInfo; - } - - public IRaCISDBContext CreateDbContext() - { - var context = _pooledFactory.CreateDbContext(); - context._userInfo = _userInfo; - return context; - } - } + // public IRaCISDBContext CreateDbContext() + // { + // var context = _pooledFactory.CreateDbContext(); + // context._userInfo = _userInfo; + // return context; + // } + //} public class IRaCISDBContext : DbContext { - public IUserInfo _userInfo; + private IUserInfo _userInfo; - public readonly ILogger _logger; + private readonly ILogger _logger; public IRaCISDBContext(DbContextOptions options, IUserInfo userInfo, ILogger logger