forked from EasyAbp/Abp.WeChat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
133 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/MiniProgram/EasyAbp.Abp.WeChat.MiniProgram/AbpWeChatMiniProgramModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,27 @@ | ||
using Volo.Abp.Modularity; | ||
using EasyAbp.Abp.WeChat.Common; | ||
using EasyAbp.Abp.WeChat.MiniProgram.Infrastructure.OptionsResolve; | ||
using EasyAbp.Abp.WeChat.MiniProgram.Infrastructure.OptionsResolve.Contributors; | ||
|
||
namespace EasyAbp.Abp.WeChat.MiniProgram | ||
{ | ||
[DependsOn(typeof(AbpWeChatCommonModule))] | ||
public class AbpWeChatMiniProgramModule : AbpModule | ||
{ | ||
public override void PostConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
Configure<AbpWeChatMiniProgramResolveOptions>(options => | ||
{ | ||
if (!options.Contributors.Exists(x => x.Name == ConfigurationOptionsResolveContributor.ContributorName)) | ||
{ | ||
options.Contributors.Add(new ConfigurationOptionsResolveContributor()); | ||
} | ||
|
||
if (!options.Contributors.Exists(x => x.Name == AsyncLocalOptionsResolveContributor.ContributorName)) | ||
{ | ||
options.Contributors.Insert(0, new AsyncLocalOptionsResolveContributor()); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...Program/Infrastructure/OptionsResolve/Contributors/AsyncLocalOptionsResolveContributor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Volo.Abp; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace EasyAbp.Abp.WeChat.MiniProgram.Infrastructure.OptionsResolve.Contributors | ||
{ | ||
public class AsyncLocalOptionsResolveContributor : IWeChatMiniProgramOptionsResolveContributor | ||
{ | ||
public const string ContributorName = "AsyncLocal"; | ||
|
||
public string Name => ContributorName; | ||
|
||
public Task ResolveAsync(WeChatMiniProgramOptionsResolveContext context) | ||
{ | ||
var asyncLocal = context.ServiceProvider.GetRequiredService<IWeChatMiniProgramAsyncLocalAccessor>(); | ||
|
||
if (asyncLocal.Current != null) | ||
{ | ||
context.Options = asyncLocal.Current; | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
public interface IWeChatMiniProgramAsyncLocalAccessor | ||
{ | ||
IWeChatMiniProgramOptions Current { get; set; } | ||
} | ||
|
||
public class WeChatMiniProgramAsyncLocalAccessor : IWeChatMiniProgramAsyncLocalAccessor, ISingletonDependency | ||
{ | ||
public IWeChatMiniProgramOptions Current | ||
{ | ||
get => _asyncLocal.Value; | ||
set => _asyncLocal.Value = value; | ||
} | ||
|
||
private readonly AsyncLocal<IWeChatMiniProgramOptions> _asyncLocal; | ||
|
||
public WeChatMiniProgramAsyncLocalAccessor() | ||
{ | ||
_asyncLocal = new AsyncLocal<IWeChatMiniProgramOptions>(); | ||
} | ||
} | ||
|
||
public interface IWeChatMiniProgramAsyncLocal | ||
{ | ||
IWeChatMiniProgramOptions CurrentOptions { get; } | ||
|
||
IDisposable Change(IWeChatMiniProgramOptions weChatMiniProgramOptions); | ||
} | ||
|
||
public class WeChatMiniProgramAsyncLocal : IWeChatMiniProgramAsyncLocal, ITransientDependency | ||
{ | ||
public IWeChatMiniProgramOptions CurrentOptions { get; private set; } | ||
|
||
private readonly IWeChatMiniProgramAsyncLocalAccessor _weChatMiniProgramAsyncLocalAccessor; | ||
|
||
public WeChatMiniProgramAsyncLocal(IWeChatMiniProgramAsyncLocalAccessor weChatMiniProgramAsyncLocalAccessor) | ||
{ | ||
_weChatMiniProgramAsyncLocalAccessor = weChatMiniProgramAsyncLocalAccessor; | ||
|
||
CurrentOptions = weChatMiniProgramAsyncLocalAccessor.Current; | ||
} | ||
|
||
public IDisposable Change(IWeChatMiniProgramOptions weChatMiniProgramOptions) | ||
{ | ||
var parentScope = _weChatMiniProgramAsyncLocalAccessor.Current; | ||
|
||
_weChatMiniProgramAsyncLocalAccessor.Current = weChatMiniProgramOptions; | ||
|
||
return new DisposeAction(() => | ||
{ | ||
_weChatMiniProgramAsyncLocalAccessor.Current = parentScope; | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters