From eb9ed5c76f7b56e2dc4a2c3602672baf14ac0411 Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Wed, 4 Dec 2024 22:40:15 +0800 Subject: [PATCH 1/2] [2024-12-04] v3.1.0-beta3 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run --- .../Senparc.CO2NET.Sample.net8.csproj | 2 +- .../Senparc.CO2NET.APM.csproj | 3 +- src/Senparc.CO2NET.AspNet/Register.cs | 73 ++++----- .../RegisterServices/RegisterService.cs | 5 +- .../Senparc.CO2NET.AspNet.csproj | 3 +- .../InitTests.cs | 16 +- .../Senparc.CO2NET.Cache.CsRedis.csproj | 23 +-- .../Senparc.CO2NET.Cache.Dapr.csproj | 5 +- .../Senparc.CO2NET.Cache.Memcached.csproj | 5 +- .../Senparc.CO2NET.Cache.Redis.RedLock.csproj | 3 +- .../InitTests.cs | 15 +- .../Senparc.CO2NET.Cache.Redis.csproj | 139 +++++++++--------- .../Senparc.CO2NET.MagicObject.csproj | 3 +- src/Senparc.CO2NET.Tests/BaseTest.cs | 5 +- .../Utilities/HttpUtility/PostTests.cs | 2 +- .../StreamUtility/StreamUtilityTests.cs | 10 +- .../Senparc.CO2NET.WebApi.Tests.csproj | 2 +- .../Senparc.CO2NET.WebApi.csproj | 7 +- src/Senparc.CO2NET/Config.cs | 2 +- .../RegisterServices/RegisterService.cs | 15 +- .../RegisterServiceExtension.cs | 7 + src/Senparc.CO2NET/Senparc.CO2NET.csproj | 3 +- 22 files changed, 188 insertions(+), 160 deletions(-) diff --git a/Sample/Senparc.CO2NET.Sample.net8/Senparc.CO2NET.Sample.net8.csproj b/Sample/Senparc.CO2NET.Sample.net8/Senparc.CO2NET.Sample.net8.csproj index 32b6a8c5..f7e4ebb2 100644 --- a/Sample/Senparc.CO2NET.Sample.net8/Senparc.CO2NET.Sample.net8.csproj +++ b/Sample/Senparc.CO2NET.Sample.net8/Senparc.CO2NET.Sample.net8.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/Senparc.CO2NET.APM/Senparc.CO2NET.APM.csproj b/src/Senparc.CO2NET.APM/Senparc.CO2NET.APM.csproj index 03acdce5..e7fc0cdd 100644 --- a/src/Senparc.CO2NET.APM/Senparc.CO2NET.APM.csproj +++ b/src/Senparc.CO2NET.APM/Senparc.CO2NET.APM.csproj @@ -1,7 +1,7 @@  net462;netstandard2.0 - 2.0.1-beta1 + 2.1.0-beta1 Senparc.CO2NET.APM Senparc.CO2NET.APM true @@ -37,6 +37,7 @@ v1.1.0 APM is disabled by default (EnableAPM = false) [2024-09-11] v1.4.6 Update Cache, remove InsertToCache(), add Count(prefix) [2024-11-28] v2.0.1-beta1 Add UseLowerCaseApiName property for SenparcSetting + [2024-12-04] v2.1.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run diff --git a/src/Senparc.CO2NET.AspNet/Register.cs b/src/Senparc.CO2NET.AspNet/Register.cs index 3a3e0925..cb55ec5d 100644 --- a/src/Senparc.CO2NET.AspNet/Register.cs +++ b/src/Senparc.CO2NET.AspNet/Register.cs @@ -12,28 +12,29 @@ Modification Identifier: Senparc - 20240728 Modification Description: v1.4.0 .NET 6.0 and .NET 8.0 assemblies no longer depend on Microsoft.AspNetCore.Hosting.Abstractions and Microsoft.AspNetCore.Http.Abstractions -----------------------------------------------------------------*/ - -#if !NET462 -using Microsoft.AspNetCore.Builder; -using System; -using System.Collections.Generic; -using System.Text; -using Senparc.CO2NET.Cache; -using Senparc.CO2NET.RegisterServices; -using Microsoft.Extensions.Options; -using Microsoft.Extensions.DependencyInjection; -#endif - -namespace Senparc.CO2NET.AspNet -{ +----------------------------------------------------------------*/ + + +#if !NET462 +using Microsoft.AspNetCore.Builder; +using System; +using System.Collections.Generic; +using System.Text; +using Senparc.CO2NET.Cache; +using Senparc.CO2NET.RegisterServices; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.DependencyInjection; +#endif + +namespace Senparc.CO2NET.AspNet +{ /// /// Senparc.CO2NET.AspNet Basic Information Registration /// - public static class Register - { -#if !NET462 - + public static class Register + { +#if !NET462 + /// /// Start Senparc.CO2NET initialization parameter process (ASP.NET Core) /// @@ -46,21 +47,21 @@ public static class Register /// (LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered), /// If set to null (note: not delegate returns null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies /// - public static IRegisterService UseSenparcGlobal(this IApplicationBuilder registerService, - Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/ env, - SenparcSetting senparcSetting = null, - Action registerConfigure = null, - bool autoScanExtensionCacheStrategies = false, - Func> extensionCacheStrategiesFunc = null) - { - senparcSetting = senparcSetting ?? registerService.ApplicationServices.GetService>().Value; - + public static IRegisterService UseSenparcGlobal(this IApplicationBuilder registerService, + Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/ env, + SenparcSetting senparcSetting = null, + Action registerConfigure = null, + bool autoScanExtensionCacheStrategies = false, + Func> extensionCacheStrategiesFunc = null) + { + senparcSetting = senparcSetting ?? Senparc.CO2NET.Config.SenparcSetting; /*registerService.ApplicationServices.GetService>().Value;*/ + //Initialize the global RegisterService object and store SenparcSetting information - var register = Senparc.CO2NET.AspNet.RegisterServices. - RegisterService.Start(env, senparcSetting); - - return Senparc.CO2NET.Register.UseSenparcGlobal(senparcSetting, registerConfigure, autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); - } -#endif - } -} + var register = Senparc.CO2NET.AspNet.RegisterServices. + RegisterService.Start(env/*, senparcSetting*/); + + return Senparc.CO2NET.Register.UseSenparcGlobal(senparcSetting, registerConfigure, autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); + } +#endif + } +} diff --git a/src/Senparc.CO2NET.AspNet/RegisterServices/RegisterService.cs b/src/Senparc.CO2NET.AspNet/RegisterServices/RegisterService.cs index 1bbdabe1..89115a1e 100644 --- a/src/Senparc.CO2NET.AspNet/RegisterServices/RegisterService.cs +++ b/src/Senparc.CO2NET.AspNet/RegisterServices/RegisterService.cs @@ -37,11 +37,10 @@ public static class RegisterService /// Start Senparc.CO2NET SDK initialization parameter process (.NET Core), supports ASP.NET Core /// /// IHostingEnvironment, console programs can input null, - /// /// public static Senparc.CO2NET.RegisterServices.RegisterService Start( - Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/ env, - SenparcSetting senparcSetting) + Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/ env + , SenparcSetting senparcSetting = null) { //Provide website root directory if (env != null && env.ContentRootPath != null) diff --git a/src/Senparc.CO2NET.AspNet/Senparc.CO2NET.AspNet.csproj b/src/Senparc.CO2NET.AspNet/Senparc.CO2NET.AspNet.csproj index 06ce2793..3e41a4d1 100644 --- a/src/Senparc.CO2NET.AspNet/Senparc.CO2NET.AspNet.csproj +++ b/src/Senparc.CO2NET.AspNet/Senparc.CO2NET.AspNet.csproj @@ -1,7 +1,7 @@  net462;netstandard2.0;netstandard2.1;net8.0 - 2.0.1-beta1 + 2.1.0-beta1 Senparc.CO2NET.AspNet Senparc.CO2NET.AspNet true @@ -33,6 +33,7 @@ [2024-09-11] v1.4.3 Update Cache, remove InsertToCache(), add Count(prefix) [2024-10-07] v1.5.0 Stop supporting .NET 6.0 [2024-11-28] v2.0.1-beta1 Add UseLowerCaseApiName property for SenparcSetting + [2024-12-04] v2.1.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test diff --git a/src/Senparc.CO2NET.Cache.CsRedis.Tests/InitTests.cs b/src/Senparc.CO2NET.Cache.CsRedis.Tests/InitTests.cs index 95aa7816..77b240e1 100644 --- a/src/Senparc.CO2NET.Cache.CsRedis.Tests/InitTests.cs +++ b/src/Senparc.CO2NET.Cache.CsRedis.Tests/InitTests.cs @@ -35,15 +35,19 @@ public void AutoRegisterConfigurationTest() var redisServer = "localhost:6379"; - var senparcSetting = new SenparcSetting() - { - IsDebug = true, - Cache_Redis_Configuration = redisServer - }; + Senparc.CO2NET.Config.SenparcSetting.IsDebug = true; + Senparc.CO2NET.Config.SenparcSetting.Cache_Redis_Configuration = redisServer; + + + //var senparcSetting = new SenparcSetting() + //{ + // IsDebug = true, + // Cache_Redis_Configuration = redisServer + //}; var registerService = Senparc.CO2NET.AspNet.RegisterServices. - RegisterService.Start(mockEnv.Object, senparcSetting) + RegisterService.Start(mockEnv.Object/*, senparcSetting*/) .UseSenparcGlobal(); Assert.AreEqual(null, RedisManager.ConfigurationOption);// Not registered yet diff --git a/src/Senparc.CO2NET.Cache.CsRedis/Senparc.CO2NET.Cache.CsRedis.csproj b/src/Senparc.CO2NET.Cache.CsRedis/Senparc.CO2NET.Cache.CsRedis.csproj index 82302cb1..c627c22d 100644 --- a/src/Senparc.CO2NET.Cache.CsRedis/Senparc.CO2NET.Cache.CsRedis.csproj +++ b/src/Senparc.CO2NET.Cache.CsRedis/Senparc.CO2NET.Cache.CsRedis.csproj @@ -1,16 +1,16 @@  net462;netstandard2.0 - 2.1.1-beta1 + 2.2.0-beta1 Senparc.CO2NET.Cache.CsRedis Senparc.CO2NET.Cache.CsRedis true - CONET cache strategy - Redis module + CONET cache strategy - Redis module - CO2NET open source project: - https://github.com/Senparc/Senparc.CO2NET - + CO2NET open source project: + https://github.com/Senparc/Senparc.CO2NET + Senparc Copyright © 2004~2024 Senparc.CO2NET,Cache,Redis,CO2NET,盛派 Jeffrey Su @@ -22,14 +22,15 @@ https://github.com/JeffreySu/WeiXinMPSDK icon.jpg - v0.1.0 Genesis - v0.5.2 BaseRedisObjectCacheStrategy destructor performs null value check and adds "#{Cache_Redis_Configuration}#" filter check - v1.1.4 RedisObjectCacheStrategy and RedisHashSetObjectCacheStrategy.Get() methods add pure string check - v1.2.5 Fix bug where GetAllByPrefixAsync(key) method automatically retrieves all keys - [2024-09-11] v1.2.6 Update Cache, remove InsertToCache(), add Count(prefix) + v0.1.0 Genesis + v0.5.2 BaseRedisObjectCacheStrategy destructor performs null value check and adds "#{Cache_Redis_Configuration}#" filter check + v1.1.4 RedisObjectCacheStrategy and RedisHashSetObjectCacheStrategy.Get() methods add pure string check + v1.2.5 Fix bug where GetAllByPrefixAsync(key) method automatically retrieves all keys + [2024-09-11] v1.2.6 Update Cache, remove InsertToCache(), add Count(prefix) [2024-10-24] v2.0.1-beta1 fix: GetCountAsync(string prefix) #306 Thanks to @rendyu [2024-11-28] v2.1.1-beta1 Add UseLowerCaseApiName property for SenparcSetting - + [2024-12-04] v2.2.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run + https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test diff --git a/src/Senparc.CO2NET.Cache.Dapr/Senparc.CO2NET.Cache.Dapr.csproj b/src/Senparc.CO2NET.Cache.Dapr/Senparc.CO2NET.Cache.Dapr.csproj index fb91e34b..d6fc5047 100644 --- a/src/Senparc.CO2NET.Cache.Dapr/Senparc.CO2NET.Cache.Dapr.csproj +++ b/src/Senparc.CO2NET.Cache.Dapr/Senparc.CO2NET.Cache.Dapr.csproj @@ -1,7 +1,7 @@  net8.0 - 1.0.1-beta1 + 1.1.0-beta1 Senparc.CO2NET.Cache.Dapr Senparc.CO2NET.Cache.Dapr true @@ -25,7 +25,8 @@ v0.1.0 Genesis [2024-09-11] v0.1.3 Update Cache, remove InsertToCache(), add Count(prefix) [2024-11-28] v1.0.1-beta1 Add UseLowerCaseApiName property for SenparcSetting - + [2024-12-04] v1.1.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run + https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test diff --git a/src/Senparc.CO2NET.Cache.Memcached/Senparc.CO2NET.Cache.Memcached.csproj b/src/Senparc.CO2NET.Cache.Memcached/Senparc.CO2NET.Cache.Memcached.csproj index ffb2a643..af0cfdae 100644 --- a/src/Senparc.CO2NET.Cache.Memcached/Senparc.CO2NET.Cache.Memcached.csproj +++ b/src/Senparc.CO2NET.Cache.Memcached/Senparc.CO2NET.Cache.Memcached.csproj @@ -1,7 +1,7 @@  net462;netstandard2.0;net8.0 - 5.0.1-beta1 + 5.1.0-beta1 Senparc.CO2NET.Cache.Memcached Senparc.CO2NET.Cache.Memcached @@ -91,7 +91,8 @@ [2024-09-11] v4.2.5 Update Cache, remove InsertToCache(), add Count(prefix) [2024-10-07] v4.3.0 Stop supporting .NET 6.0 [2024-11-28] v5.0.1-beta1 Add UseLowerCaseApiName property for SenparcSetting - + [2024-12-04] v5.1.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run + https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test diff --git a/src/Senparc.CO2NET.Cache.Redis.RedLock/redlock-cs/src/Senparc.CO2NET.Cache.Redis.RedLock.csproj b/src/Senparc.CO2NET.Cache.Redis.RedLock/redlock-cs/src/Senparc.CO2NET.Cache.Redis.RedLock.csproj index 035a8d46..4f7110b5 100644 --- a/src/Senparc.CO2NET.Cache.Redis.RedLock/redlock-cs/src/Senparc.CO2NET.Cache.Redis.RedLock.csproj +++ b/src/Senparc.CO2NET.Cache.Redis.RedLock/redlock-cs/src/Senparc.CO2NET.Cache.Redis.RedLock.csproj @@ -1,7 +1,7 @@  net462;netstandard2.0 - 4.0.1-beta1 + 4.1.0-beta1 Senparc.CO2NET.Cache.Redis.RedLock Senparc.CO2NET.Cache.Redis.RedLock true @@ -56,6 +56,7 @@ v2.2.1 Used .ConfigureAwait(false) to avoid asynchronous deadlock v2.2.4 Provided signed nuget package (.snupkg) [2024-11-28] v4.0.1-beta1 Add UseLowerCaseApiName property for SenparcSetting + [2024-12-04] v4.1.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test diff --git a/src/Senparc.CO2NET.Cache.Redis.Tests/InitTests.cs b/src/Senparc.CO2NET.Cache.Redis.Tests/InitTests.cs index a3839e73..3588510c 100644 --- a/src/Senparc.CO2NET.Cache.Redis.Tests/InitTests.cs +++ b/src/Senparc.CO2NET.Cache.Redis.Tests/InitTests.cs @@ -35,15 +35,18 @@ public void AutoRegisterConfigurationTest() var redisServer = "localhost:6379"; - var senparcSetting = new SenparcSetting() - { - IsDebug = true, - Cache_Redis_Configuration = redisServer - }; + Senparc.CO2NET.Config.SenparcSetting.IsDebug = true; + Senparc.CO2NET.Config.SenparcSetting.Cache_Redis_Configuration = redisServer; + //var senparcSetting = new SenparcSetting() + //{ + // IsDebug = true, + // Cache_Redis_Configuration = redisServer + //}; + var registerService = Senparc.CO2NET.AspNet.RegisterServices. - RegisterService.Start(mockEnv.Object, senparcSetting) + RegisterService.Start(mockEnv.Object/*, senparcSetting*/) .UseSenparcGlobal(); Assert.AreEqual(null, RedisManager.ConfigurationOption);// Not registered yet diff --git a/src/Senparc.CO2NET.Cache.Redis/Senparc.CO2NET.Cache.Redis.csproj b/src/Senparc.CO2NET.Cache.Redis/Senparc.CO2NET.Cache.Redis.csproj index c6cfbd9f..2f6da668 100644 --- a/src/Senparc.CO2NET.Cache.Redis/Senparc.CO2NET.Cache.Redis.csproj +++ b/src/Senparc.CO2NET.Cache.Redis/Senparc.CO2NET.Cache.Redis.csproj @@ -1,16 +1,16 @@  net462;netstandard2.0 - 5.1.1-beta1 + 5.2.0-beta1 Senparc.CO2NET.Cache.Redis Senparc.CO2NET.Cache.Redis true - WeChat Public Account - Redis Module + WeChat Public Account - Redis Module - Senparc.Weixin SDK Open Source Project: - https://github.com/JeffreySu/WeiXinMPSDK - + Senparc.Weixin SDK Open Source Project: + https://github.com/JeffreySu/WeiXinMPSDK + Senparc Copyright © 2004~2024 Senparc.CO2NET,Cache,Redis,CO2NET,盛派 Jeffrey Su @@ -22,92 +22,93 @@ https://github.com/JeffreySu/WeiXinMPSDK icon.jpg - v0.1.0 - Provide distributed cache support - Due to a bug in the StackExchange.Redis library, the .NET 4.0 version is temporarily not provided + v0.1.0 + Provide distributed cache support + Due to a bug in the StackExchange.Redis library, the .NET 4.0 version is temporarily not provided - v0.1.1 - Optimize cache strategy, improve delete method. + v0.1.1 + Optimize cache strategy, improve delete method. - v0.2.0 - Refactor cache strategy, provide distributed lock + v0.2.0 + Refactor cache strategy, provide distributed lock - v0.2.1 - Optimize methods and interfaces + v0.2.1 + Optimize methods and interfaces - v0.0.2 - Refactor cache key namespace rules, add Config.DefaultCacheNamespace + v0.0.2 + Refactor cache key namespace rules, add Config.DefaultCacheNamespace - v0.2.3 - Release stable version + v0.2.3 + Release stable version - v1.0.0 - Modify cache strategy, change storage type from String to Hash + v1.0.0 + Modify cache strategy, change storage type from String to Hash - v1.1.0 - Refactor cache, add ObjectCacheStrategy + v1.1.0 + Refactor cache, add ObjectCacheStrategy - v1.2.0 Refactor distributed lock - v1.2.1 Provide .net core version - v1.2.2 Provide both .net core and .net 4.6.1 versions + v1.2.0 Refactor distributed lock + v1.2.1 Provide .net core version + v1.2.2 Provide both .net core and .net 4.6.1 versions - v1.3.0 Support .NET Core + v1.3.0 Support .NET Core - v1.4.0-beta1 Support .NET Core 2.0 + v1.4.0-beta1 Support .NET Core 2.0 - v1.5.0 Stop generating separate versions for .net core 1.1 - v1.5.1 Provide RegisterServices for quick registration + v1.5.0 Stop generating separate versions for .net core 1.1 + v1.5.1 Provide RegisterServices for quick registration - v1.6.0 Provide full binary serialization support under .NET Core (support delegate parameters) - v1.6.1 Optimize binary serialization support + v1.6.0 Provide full binary serialization support under .NET Core (support delegate parameters) + v1.6.1 Optimize binary serialization support - v1.7.0-rc1 Support .NET Core 2.1.0-rc1-final - v1.7.2-rc1 Improve conditional compilation for .net core 2.1 + v1.7.0-rc1 Support .NET Core 2.1.0-rc1-final + v1.7.2-rc1 Improve conditional compilation for .net core 2.1 - v1.7.5 Release official version supporting .net core 2.1 + v1.7.5 Release official version supporting .net core 2.1 - v2.0.0 Introduce Senparc.CO2NET, support Senparc.Weixin v5.0 + v2.0.0 Introduce Senparc.CO2NET, support Senparc.Weixin v5.0 - ======== CO2NET Migration ======== + ======== CO2NET Migration ======== - v2.0.0 Refactor Redis cache strategy - v2.0.1 Support CO2NET v0.1.1 - v2.0.2 Support CO2NET v0.1.2 - v2.0.3 Support CO2NET v0.1.3 - v2.0.5 Support CO2NET v0.1.5 - v2.0.9 Support CO2NET v0.1.9 + v2.0.0 Refactor Redis cache strategy + v2.0.1 Support CO2NET v0.1.1 + v2.0.2 Support CO2NET v0.1.2 + v2.0.3 Support CO2NET v0.1.3 + v2.0.5 Support CO2NET v0.1.5 + v2.0.9 Support CO2NET v0.1.9 - v3.0.0 - 1. Separate HashSet and Key-Value two different formats of cache: RedisHashSetObjectCacheStrategy and RedisObjectCacheStrategy - 2. Provide new cache expiration strategy + v3.0.0 + 1. Separate HashSet and Key-Value two different formats of cache: RedisHashSetObjectCacheStrategy and RedisObjectCacheStrategy + 2. Provide new cache expiration strategy - v3.1.0 - 1. Mark Register.RegisterCacheRedis as obsolete - 2. Add Register.SetConfigurationOption() method - 3. Add Register.UseKeyValueRedisNow() method - 4. Add Register.UseHashRedisNow() method - 5. Implement automatic acquisition and registration of Redis cache service connection information from Config.SenparcSetting - v3.2.0 Upgrade StackExchange.Redis to 2.0.513 - v3.3.0 Use .NETStandard2.0 to support .NET Core uniformly, abandon separate adaptation for .NET Core 1.x - v3.4.0 Support .net 4.6.1 version - v3.4.3 Upgrade StackExchange.Redis to the latest version - v3.5.0 Provide asynchronous cache interface - v3.5.1 Use .ConfigureAwait(false) to avoid asynchronous deadlock - v3.5.4 - 1. fix bug: Add database index value to GetServer().Keys() method - 2. Constrain the upper limit of GetServer().Keys() method: 99999 - v3.5.5 Support new version of CO2NET, provide signed nuget package (.snupkg) - v3.6.0 Support new version of CO2NET, support .NET Core 3.0 - v3.6.102 Support new version of CO2NET - v3.6.103 Support new version of CO2NET, optimize asynchronous methods - v3.11.2 BaseRedisObjectCacheStrategy destructor performs null value check, and adds "#{Cache_Redis_Configuration}#" filter check - v4.1.3 Add pure string check to RedisObjectCacheStrategy and RedisHashSetObjectCacheStrategy.Get() methods - v4.2.5 Fix bug where GetAllByPrefixAsync(key) method would automatically retrieve all keys + v3.1.0 + 1. Mark Register.RegisterCacheRedis as obsolete + 2. Add Register.SetConfigurationOption() method + 3. Add Register.UseKeyValueRedisNow() method + 4. Add Register.UseHashRedisNow() method + 5. Implement automatic acquisition and registration of Redis cache service connection information from Config.SenparcSetting + v3.2.0 Upgrade StackExchange.Redis to 2.0.513 + v3.3.0 Use .NETStandard2.0 to support .NET Core uniformly, abandon separate adaptation for .NET Core 1.x + v3.4.0 Support .net 4.6.1 version + v3.4.3 Upgrade StackExchange.Redis to the latest version + v3.5.0 Provide asynchronous cache interface + v3.5.1 Use .ConfigureAwait(false) to avoid asynchronous deadlock + v3.5.4 + 1. fix bug: Add database index value to GetServer().Keys() method + 2. Constrain the upper limit of GetServer().Keys() method: 99999 + v3.5.5 Support new version of CO2NET, provide signed nuget package (.snupkg) + v3.6.0 Support new version of CO2NET, support .NET Core 3.0 + v3.6.102 Support new version of CO2NET + v3.6.103 Support new version of CO2NET, optimize asynchronous methods + v3.11.2 BaseRedisObjectCacheStrategy destructor performs null value check, and adds "#{Cache_Redis_Configuration}#" filter check + v4.1.3 Add pure string check to RedisObjectCacheStrategy and RedisHashSetObjectCacheStrategy.Get() methods + v4.2.5 Fix bug where GetAllByPrefixAsync(key) method would automatically retrieve all keys - [2024-09-11] v4.2.6 Update Cache, remove InsertToCache(), add Count(prefix) + [2024-09-11] v4.2.6 Update Cache, remove InsertToCache(), add Count(prefix) [2024-10-24] v5.0.1-beta1 fix: GetCountAsync(string prefix) #306 Thanks to @rendyu [2024-11-28] v5.1.1-beta1 Add UseLowerCaseApiName property for SenparcSetting - + [2024-12-04] v5.2.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run + https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test diff --git a/src/Senparc.CO2NET.MagicObject/Senparc.CO2NET.MagicObject.csproj b/src/Senparc.CO2NET.MagicObject/Senparc.CO2NET.MagicObject.csproj index 7340af61..d6e62d0c 100644 --- a/src/Senparc.CO2NET.MagicObject/Senparc.CO2NET.MagicObject.csproj +++ b/src/Senparc.CO2NET.MagicObject/Senparc.CO2NET.MagicObject.csproj @@ -1,7 +1,7 @@  net462;netstandard2.0;netstandard2.1 - 1.0.1-beta1 + 1.1.0-beta1 9.0 Senparc.CO2NET.MagicObject Senparc.CO2NET.MagicObject @@ -29,6 +29,7 @@ v0.1.0 Set MO.OriginalObject and MO.Object properties to public [2024-09-11] v0.1.3 Update Cache, remove InsertToCache(), add Count(prefix) [2024-11-28] v1.0.1-beta1 Add UseLowerCaseApiName property for SenparcSetting + [2024-12-04] v1.1.0-beta1 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test diff --git a/src/Senparc.CO2NET.Tests/BaseTest.cs b/src/Senparc.CO2NET.Tests/BaseTest.cs index 3548df0e..c1ae54fb 100644 --- a/src/Senparc.CO2NET.Tests/BaseTest.cs +++ b/src/Senparc.CO2NET.Tests/BaseTest.cs @@ -35,7 +35,8 @@ public static void RegisterServiceCollection() var config = configBuilder.Build(); serviceCollection.AddSenparcGlobalServices(config); - _senparcSetting = new SenparcSetting() { IsDebug = true }; + _senparcSetting = Senparc.CO2NET.Config.SenparcSetting; /*new SenparcSetting() { IsDebug = true };*/ + _senparcSetting.IsDebug = true; config.GetSection("SenparcSetting").Bind(_senparcSetting); serviceCollection.AddMemoryCache();//Use memory cache @@ -52,7 +53,7 @@ public static void RegisterServiceStart(bool autoScanExtensionCacheStrategies = var mockEnv = new Mock(); mockEnv.Setup(z => z.ContentRootPath).Returns(() => UnitTestHelper.RootPath); - registerService = Senparc.CO2NET.AspNet.RegisterServices.RegisterService.Start(mockEnv.Object, _senparcSetting) + registerService = Senparc.CO2NET.AspNet.RegisterServices.RegisterService.Start(mockEnv.Object/*, _senparcSetting*/) .UseSenparcGlobal(autoScanExtensionCacheStrategies); registerService.ChangeDefaultCacheNamespace("Senparc.CO2NET Tests"); diff --git a/src/Senparc.CO2NET.Tests/Utilities/HttpUtility/PostTests.cs b/src/Senparc.CO2NET.Tests/Utilities/HttpUtility/PostTests.cs index 42daf72a..93c51e0f 100644 --- a/src/Senparc.CO2NET.Tests/Utilities/HttpUtility/PostTests.cs +++ b/src/Senparc.CO2NET.Tests/Utilities/HttpUtility/PostTests.cs @@ -135,7 +135,7 @@ public void PostFileGetJsonTest() var fileDictionary = new Dictionary(); fileDictionary["media"] = "E:\\Senparc项目\\WeiXinMPSDK\\src\\Senparc.Weixin.Work\\Senparc.Weixin.Work.Test\\AdvancedAPIs\\Media\\中文名.txt"; - var uploadResult = CO2NET.HttpUtility.Post.PostFileGetJsonAsync(BaseTest.serviceProvider, url, null, fileDictionary, null, null, null, false).GetAwaiter().GetResult(); + var uploadResult = CO2NET.HttpUtility.Post.PostFileGetJsonAsync(BaseTest.serviceProvider, url, null, fileDictionary, null, null, null, null, false).GetAwaiter().GetResult(); Console.WriteLine(uploadResult); diff --git a/src/Senparc.CO2NET.Tests/Utilities/StreamUtility/StreamUtilityTests.cs b/src/Senparc.CO2NET.Tests/Utilities/StreamUtility/StreamUtilityTests.cs index 417d8753..fe36c7e0 100644 --- a/src/Senparc.CO2NET.Tests/Utilities/StreamUtility/StreamUtilityTests.cs +++ b/src/Senparc.CO2NET.Tests/Utilities/StreamUtility/StreamUtilityTests.cs @@ -11,7 +11,7 @@ namespace Senparc.CO2NET.Tests.Utilities public class StreamUtilityTests { string str = "Senparc is by your side"; - string baseString = "77u/55ub5rS+5Zyo5L2g6Lqr6L65"; + string baseString = "77u/U2VucGFyYyBpcyBieSB5b3VyIHNpZGU="; private MemoryStream GetStream(string content) { @@ -48,12 +48,12 @@ public void GetStreamFromBase64String() // Create a new file var ms = StreamUtility.GetStreamFromBase64String(baseString, null); - Assert.AreEqual(21, ms.Length); + Assert.AreEqual(26, ms.Length); // Open a file var file = UnitTestHelper.RootPath + "GetStreamFromBase64String.txt"; var ms2 = StreamUtility.GetStreamFromBase64String(baseString, file); - Assert.AreEqual(21, ms.Length); + Assert.AreEqual(26, ms.Length); Assert.IsTrue(File.Exists(file)); @@ -77,12 +77,12 @@ public void GetStreamFromBase64String() { // Create a new file var ms = await StreamUtility.GetStreamFromBase64StringAsync(baseString, null); - Assert.AreEqual(21, ms.Length); + Assert.AreEqual(26, ms.Length); // Open a file var file = UnitTestHelper.RootPath + "GetStreamFromBase64String_Async.txt"; var ms2 = await StreamUtility.GetStreamFromBase64StringAsync(baseString, file); - Assert.AreEqual(21, ms.Length); + Assert.AreEqual(26, ms.Length); Assert.IsTrue(File.Exists(file)); diff --git a/src/Senparc.CO2NET.WebApi.Tests/Senparc.CO2NET.WebApi.Tests.csproj b/src/Senparc.CO2NET.WebApi.Tests/Senparc.CO2NET.WebApi.Tests.csproj index 410ff7d0..c7e5267d 100644 --- a/src/Senparc.CO2NET.WebApi.Tests/Senparc.CO2NET.WebApi.Tests.csproj +++ b/src/Senparc.CO2NET.WebApi.Tests/Senparc.CO2NET.WebApi.Tests.csproj @@ -15,7 +15,7 @@ - + diff --git a/src/Senparc.CO2NET.WebApi/Senparc.CO2NET.WebApi.csproj b/src/Senparc.CO2NET.WebApi/Senparc.CO2NET.WebApi.csproj index b5f2ac12..a9e5b908 100644 --- a/src/Senparc.CO2NET.WebApi/Senparc.CO2NET.WebApi.csproj +++ b/src/Senparc.CO2NET.WebApi/Senparc.CO2NET.WebApi.csproj @@ -1,7 +1,7 @@  netstandard2.1;net8.0 - 2.0.2-beta3 + 2.1.0-beta3 latest Senparc.CO2NET.WebApi Senparc.CO2NET.WebApi @@ -46,8 +46,9 @@ 1. Add UseLowerCaseApiName to WebApiEngineOptions 2. Add unique WebApi name to duplicate method name [2024-11-27] v2.0.1-beta3 add lock to AddAndInitDynamicApi() method - [2024-11-28] v2.0.2-beta3 Add UseLowerCaseApiName property for SenparcSetting - + [2024-11-28] v2.0.2-beta3 Add UseLowerCaseApiName property for SenparcSetting + [2024-12-04] v2.1.0-beta3 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run + ..\BuildOutPut diff --git a/src/Senparc.CO2NET/Config.cs b/src/Senparc.CO2NET/Config.cs index 90d3dc42..c5cef01d 100644 --- a/src/Senparc.CO2NET/Config.cs +++ b/src/Senparc.CO2NET/Config.cs @@ -68,7 +68,7 @@ public class Config /// Global configuration /// Run RegisterServiceExtension.AddSenparcGlobalServices() in startup.cs to automatically inject /// - public static SenparcSetting SenparcSetting { get; set; } = new SenparcSetting();//TODO: Need to consider distributed scenarios, later need to store in cache + public static SenparcSetting SenparcSetting { get; internal set; } = new SenparcSetting();//TODO: Need to consider distributed scenarios, later need to store in cache /// /// Specify whether it is in Debug mode, if true, the system will automatically output logs diff --git a/src/Senparc.CO2NET/RegisterServices/RegisterService.cs b/src/Senparc.CO2NET/RegisterServices/RegisterService.cs index 11992269..04c2318b 100644 --- a/src/Senparc.CO2NET/RegisterServices/RegisterService.cs +++ b/src/Senparc.CO2NET/RegisterServices/RegisterService.cs @@ -69,12 +69,15 @@ public class RegisterService : IRegisterService { public static RegisterService Object { get; internal set; } - private RegisterService() : this(null) { } + //private RegisterService() : this(null) { } - private RegisterService(SenparcSetting senparcSetting) + private RegisterService(SenparcSetting senparcSetting = null) { //Senparc.CO2NET SDK configuration - Senparc.CO2NET.Config.SenparcSetting = senparcSetting ?? new SenparcSetting(); + if (senparcSetting!=null) + { + Senparc.CO2NET.Config.SenparcSetting = senparcSetting; + } } #if !NET462 @@ -89,7 +92,7 @@ private RegisterService(SenparcSetting senparcSetting) /// /// /// - public static RegisterService Start(SenparcSetting senparcSetting) + public static RegisterService Start(SenparcSetting senparcSetting=null) { var register = new RegisterService(senparcSetting); @@ -104,9 +107,9 @@ public static RegisterService Start(SenparcSetting senparcSetting) /// Start Senparc.CO2NET SDK initialization parameter process /// /// - public static RegisterService Start(SenparcSetting senparcSetting) + public static RegisterService Start(/*SenparcSetting senparcSetting*/) { - var register = new RegisterService(senparcSetting); + var register = new RegisterService(/*senparcSetting*/); //Provide website root directory Senparc.CO2NET.Config.RootDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; diff --git a/src/Senparc.CO2NET/RegisterServices/RegisterServiceExtension.cs b/src/Senparc.CO2NET/RegisterServices/RegisterServiceExtension.cs index fb8aafc6..4f7948d5 100644 --- a/src/Senparc.CO2NET/RegisterServices/RegisterServiceExtension.cs +++ b/src/Senparc.CO2NET/RegisterServices/RegisterServiceExtension.cs @@ -95,6 +95,13 @@ public static IServiceCollection AddSenparcGlobalServices(this IServiceCollectio SenparcDI.GlobalServiceCollection = serviceCollection; serviceCollection.Configure(configuration.GetSection("SenparcSetting")); + //Senparc.CO2NET SDK configuration + var senparcSetting = configuration.GetSection("SenparcSetting").Get(); + if (senparcSetting != null) + { + Senparc.CO2NET.Config.SenparcSetting = senparcSetting; + } + serviceCollection.AddTransient(s => CacheStrategyFactory.GetObjectCacheStrategyInstance()); serviceCollection.AddScoped(); diff --git a/src/Senparc.CO2NET/Senparc.CO2NET.csproj b/src/Senparc.CO2NET/Senparc.CO2NET.csproj index 2ae6963f..29b5ada7 100644 --- a/src/Senparc.CO2NET/Senparc.CO2NET.csproj +++ b/src/Senparc.CO2NET/Senparc.CO2NET.csproj @@ -1,7 +1,7 @@  net462;netstandard2.0;netstandard2.1 - 3.0.1-beta3 + 3.1.0-beta3 10.0 Senparc.CO2NET Senparc.CO2NET @@ -143,6 +143,7 @@ [2024-10-24] v3.0.0-beta1 Upgrade to English version [2024-10-24] v3.0.0-beta3 Add ApiClient and ApiClientHelper [2024-11-28] v3.0.1-beta3 Add UseLowerCaseApiName property for SenparcSetting + [2024-12-04] v3.1.0-beta3 update Start() method, set SenparcSetting in Config when AddSenparcGlobalService() run https://github.com/Senparc/Senparc.CO2NET Debug;Release;Test From 82ae7f25b298e4c3e3c5359e730694ff14819040 Mon Sep 17 00:00:00 2001 From: JeffreySu Date: Wed, 4 Dec 2024 22:42:48 +0800 Subject: [PATCH 2/2] modify --- src/Senparc.CO2NET.AspNet/Register.cs | 73 ++++++++++++++------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/Senparc.CO2NET.AspNet/Register.cs b/src/Senparc.CO2NET.AspNet/Register.cs index 3a3e0925..9d524cd2 100644 --- a/src/Senparc.CO2NET.AspNet/Register.cs +++ b/src/Senparc.CO2NET.AspNet/Register.cs @@ -12,28 +12,29 @@ Modification Identifier: Senparc - 20240728 Modification Description: v1.4.0 .NET 6.0 and .NET 8.0 assemblies no longer depend on Microsoft.AspNetCore.Hosting.Abstractions and Microsoft.AspNetCore.Http.Abstractions -----------------------------------------------------------------*/ - -#if !NET462 -using Microsoft.AspNetCore.Builder; -using System; -using System.Collections.Generic; -using System.Text; -using Senparc.CO2NET.Cache; -using Senparc.CO2NET.RegisterServices; -using Microsoft.Extensions.Options; -using Microsoft.Extensions.DependencyInjection; -#endif - -namespace Senparc.CO2NET.AspNet -{ +----------------------------------------------------------------*/ + + +#if !NET462 +using Microsoft.AspNetCore.Builder; +using System; +using System.Collections.Generic; +using System.Text; +using Senparc.CO2NET.Cache; +using Senparc.CO2NET.RegisterServices; +using Microsoft.Extensions.Options; +using Microsoft.Extensions.DependencyInjection; +#endif + +namespace Senparc.CO2NET.AspNet +{ /// /// Senparc.CO2NET.AspNet Basic Information Registration /// - public static class Register - { -#if !NET462 - + public static class Register + { +#if !NET462 + /// /// Start Senparc.CO2NET initialization parameter process (ASP.NET Core) /// @@ -46,21 +47,21 @@ public static class Register /// (LocalContainerCacheStrategy, RedisContainerCacheStrategy, MemcacheContainerCacheStrategy are already automatically registered), /// If set to null (note: not delegate returns null, but the entire delegate parameter is null), it will automatically use reflection to scan all possible extension cache strategies /// - public static IRegisterService UseSenparcGlobal(this IApplicationBuilder registerService, - Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/ env, - SenparcSetting senparcSetting = null, - Action registerConfigure = null, - bool autoScanExtensionCacheStrategies = false, - Func> extensionCacheStrategiesFunc = null) - { - senparcSetting = senparcSetting ?? registerService.ApplicationServices.GetService>().Value; - + public static IRegisterService UseSenparcGlobal(this IApplicationBuilder registerService, + Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/ env, + SenparcSetting senparcSetting = null, + Action registerConfigure = null, + bool autoScanExtensionCacheStrategies = false, + Func> extensionCacheStrategiesFunc = null) + { + senparcSetting = senparcSetting ?? registerService.ApplicationServices.GetService>().Value; + //Initialize the global RegisterService object and store SenparcSetting information - var register = Senparc.CO2NET.AspNet.RegisterServices. - RegisterService.Start(env, senparcSetting); - - return Senparc.CO2NET.Register.UseSenparcGlobal(senparcSetting, registerConfigure, autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); - } -#endif - } -} + var register = Senparc.CO2NET.AspNet.RegisterServices. + RegisterService.Start(env, senparcSetting); + + return Senparc.CO2NET.Register.UseSenparcGlobal(senparcSetting, registerConfigure, autoScanExtensionCacheStrategies, extensionCacheStrategiesFunc); + } +#endif + } +}