Skip to content

Commit

Permalink
Weixin.All v2024.6.26.1 优化自动注册方法
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreySu committed Jun 25, 2024
1 parent 17b6374 commit 54ed427
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions Samples/MP/Senparc.Weixin.Sample.MP.Simple/GlobalUsing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
11 changes: 6 additions & 5 deletions Samples/MP/Senparc.Weixin.Sample.MP.Simple/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

//启用微信配置(必须)
var registerService = app.UseSenparcWeixin(app.Environment,
null /* 不为 null 则覆盖 appsettings 中的 SenpacSetting 配置*/,
null /* 不为 null 则覆盖 appsettings 中的 SenpacWeixinSetting 配置*/,
register => { /* CO2NET 全局配置 */ },
(register, weixinSetting) => {/* 注册公众号或其他平台信息(可以执行多次,注册多个公众号)*/},
true);
senparcSetting: null /* 不为 null 则覆盖 appsettings 中的 SenpacSetting 配置*/,
senparcWeixinSetting: null /* 不为 null 则覆盖 appsettings 中的 SenpacWeixinSetting 配置*/,
globalRegisterConfigure: register => { /* CO2NET 全局配置 */ },
weixinRegisterConfigure: (register, weixinSetting) => {/* 注册公众号或其他平台信息(可以执行多次,注册多个公众号)*/},
autoRegisterAllPlatforms: true /* 自动注册所有平台 */
);

#region 使用 MessageHadler 中间件,用于取代创建独立的 Controller

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<!--引用 Nuget 包-->
<ItemGroup>
<PackageReference Include="Senparc.Weixin.All" Version="2024.6.26" />
<PackageReference Include="Senparc.Weixin.All" Version="2024.6.26.1" />
</ItemGroup>

<!--直接引用源码-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

<!--引用 Nuget 包-->
<ItemGroup>
<PackageReference Include="Senparc.Weixin.AspNet" Version="0.8.5.8" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.18.10.6" />
<PackageReference Include="Senparc.Weixin.MP.Middleware" Version="0.8.5.7" />
<PackageReference Include="Senparc.Weixin.MP.MVC" Version="7.12.5.7" />
<PackageReference Include="Senparc.Weixin.AspNet" Version="1.2.2" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.21.2" />
<PackageReference Include="Senparc.Weixin.MP.Middleware" Version="1.2.2" />
<PackageReference Include="Senparc.Weixin.MP.MVC" Version="7.14.2" />
</ItemGroup>

<!--直接引用源码-->
Expand Down
2 changes: 1 addition & 1 deletion src/Senparc.Weixin.All/Senparc.Weixin.All.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>2024.6.26</Version>
<Version>2024.6.26.1</Version>
<LangVersion>10.0</LangVersion>
<AssemblyName>Senparc.Weixin.All</AssemblyName>
<RootNamespace>Senparc.Weixin.All</RootNamespace>
Expand Down
24 changes: 24 additions & 0 deletions src/Senparc.Weixin.All/WeixinEntensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<IRegisterService/*, SenparcSetting*/> globalRegisterConfigure,
Action<IRegisterService, SenparcWeixinSetting> weixinRegisterConfigure,
bool autoRegisterAllPlatforms,

//CO2NET 全局设置
bool autoScanExtensionCacheStrategies = false,
Func<List<IDomainExtensionCacheStrategy>> extensionCacheStrategiesFunc = null
)
{
//进行全局注册
var registerService = app.UseSenparcWeixin(env, senparcSetting, senparcWeixinSetting, globalRegisterConfigure, weixinRegisterConfigure, autoRegisterAllPlatforms, autoScanExtensionCacheStrategies);

//进行自动注册
registerService.UseSenparcWeixin(senparcWeixinSetting, weixinRegisterConfigure, autoRegisterAllPlatforms);

return registerService;
}

/// <summary>
/// 是否已经设置为有效的参数
/// </summary>
Expand Down

0 comments on commit 54ed427

Please sign in to comment.