diff --git a/Samples/MP/Senparc.Weixin.Sample.MP.Simple/GlobalUsing.cs b/Samples/MP/Senparc.Weixin.Sample.MP.Simple/GlobalUsing.cs index 4da639697a..e11af54c7f 100644 --- a/Samples/MP/Senparc.Weixin.Sample.MP.Simple/GlobalUsing.cs +++ b/Samples/MP/Senparc.Weixin.Sample.MP.Simple/GlobalUsing.cs @@ -6,4 +6,5 @@ global using Senparc.Weixin.Sample.MP; global using Microsoft.Extensions.Options; global using Senparc.Weixin.Entities; +global using Senparc.Weixin.All; global using Microsoft.Extensions.FileProviders; diff --git a/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Program.cs b/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Program.cs index bbd0f2cfaf..c6d5fe1bea 100644 --- a/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Program.cs +++ b/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Program.cs @@ -17,19 +17,14 @@ #region 启用微信配置(一句代码) -//手动获取配置信息可使用以下方法 -//var senparcWeixinSetting = app.Services.GetService>()!.Value; - //启用微信配置(必须) var registerService = app.UseSenparcWeixin(app.Environment, - null /* 不为 null 则覆盖 appsettings 中的 SenpacSetting 配置*/, - null /* 不为 null 则覆盖 appsettings 中的 SenpacWeixinSetting 配置*/, - register => { /* CO2NET 全局配置 */ }, - (register, weixinSetting) => -{ - //注册公众号信息(可以执行多次,注册多个公众号) - register.RegisterMpAccount(weixinSetting, "【盛派网络小助手】公众号"); -}); + senparcSetting: null /* 不为 null 则覆盖 appsettings 中的 SenpacSetting 配置*/, + senparcWeixinSetting: null /* 不为 null 则覆盖 appsettings 中的 SenpacWeixinSetting 配置*/, + globalRegisterConfigure: register => { /* CO2NET 全局配置 */ }, + weixinRegisterConfigure: (register, weixinSetting) => {/* 注册公众号或其他平台信息(可以执行多次,注册多个公众号)*/}, + autoRegisterAllPlatforms: true /* 自动注册所有平台 */ + ); #region 使用 MessageHadler 中间件,用于取代创建独立的 Controller diff --git a/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Senparc.Weixin.Sample.MP.Simple.csproj b/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Senparc.Weixin.Sample.MP.Simple.csproj index fdd53f18a6..a01355fd89 100644 --- a/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Senparc.Weixin.Sample.MP.Simple.csproj +++ b/Samples/MP/Senparc.Weixin.Sample.MP.Simple/Senparc.Weixin.Sample.MP.Simple.csproj @@ -20,10 +20,7 @@ - - - - + diff --git a/Samples/MP/Senparc.Weixin.Sample.MP/Senparc.Weixin.Sample.MP.csproj b/Samples/MP/Senparc.Weixin.Sample.MP/Senparc.Weixin.Sample.MP.csproj index 7923b5bf82..3352801082 100644 --- a/Samples/MP/Senparc.Weixin.Sample.MP/Senparc.Weixin.Sample.MP.csproj +++ b/Samples/MP/Senparc.Weixin.Sample.MP/Senparc.Weixin.Sample.MP.csproj @@ -24,10 +24,10 @@ - - - - + + + + diff --git a/src/Senparc.Weixin.All/Senparc.Weixin.All.csproj b/src/Senparc.Weixin.All/Senparc.Weixin.All.csproj index 596adebf5b..9cc796e802 100644 --- a/src/Senparc.Weixin.All/Senparc.Weixin.All.csproj +++ b/src/Senparc.Weixin.All/Senparc.Weixin.All.csproj @@ -3,7 +3,7 @@ net8.0 enable enable - 2024.6.26 + 2024.6.26.1 10.0 Senparc.Weixin.All Senparc.Weixin.All diff --git a/src/Senparc.Weixin.All/WeixinEntensions.cs b/src/Senparc.Weixin.All/WeixinEntensions.cs index 60bd781bb3..7f7ed7cb77 100644 --- a/src/Senparc.Weixin.All/WeixinEntensions.cs +++ b/src/Senparc.Weixin.All/WeixinEntensions.cs @@ -14,6 +14,9 @@ using Senparc.Weixin.TenPayV3; using Senparc.CO2NET; using Senparc.CO2NET.Extensions; +using Microsoft.AspNetCore.Builder; +using Senparc.CO2NET.Cache; +using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Senparc.Weixin.All @@ -52,6 +55,27 @@ public static IRegisterService UseSenparcWeixin(this IRegisterService registerSe return registerService; } + public static IRegisterService UseSenparcWeixin(this IApplicationBuilder app, + Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/ env, + SenparcSetting senparcSetting, SenparcWeixinSetting senparcWeixinSetting, + Action globalRegisterConfigure, + Action weixinRegisterConfigure, + bool autoRegisterAllPlatforms, + + //CO2NET 鍏ㄥ眬璁剧疆 + bool autoScanExtensionCacheStrategies = false, + Func> extensionCacheStrategiesFunc = null + ) + { + //杩涜鍏ㄥ眬娉ㄥ唽 + var registerService = app.UseSenparcWeixin(env, senparcSetting, senparcWeixinSetting, globalRegisterConfigure, weixinRegisterConfigure, autoRegisterAllPlatforms, autoScanExtensionCacheStrategies); + + //杩涜鑷姩娉ㄥ唽 + registerService.UseSenparcWeixin(senparcWeixinSetting, weixinRegisterConfigure, autoRegisterAllPlatforms); + + return registerService; + } + /// /// 鏄惁宸茬粡璁剧疆涓烘湁鏁堢殑鍙傛暟 ///