
| Revision | 0c1c33e7a727e2a0a704ad2e9da75ff9548c690f (tree) |
|---|---|
| Time | 2022-08-16 00:29:18 |
| Author | yoshy <yoshy.org.bitbucket@gz.j...> |
| Commiter | yoshy |
initial revision.
CleanAuLait から Prism 関連の実装を分離
| @@ -0,0 +1,24 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Controller; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller | |
| 5 | +{ | |
| 6 | + public class AsyncHandlerContextFactoryRegistrar : | |
| 7 | + AbstractHandlerContextFactoryRegistrar<IAsyncHandlerContextFactory, AsyncHandlerContextFactory> | |
| 8 | + { | |
| 9 | + private readonly IContainerRegistry containerRegistry; | |
| 10 | + | |
| 11 | + public AsyncHandlerContextFactoryRegistrar(IContainerRegistry containerRegistry) | |
| 12 | + { | |
| 13 | + this.containerRegistry = containerRegistry; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public override void Register() | |
| 17 | + { | |
| 18 | + var factory = CreateFactoryFactory(); | |
| 19 | + | |
| 20 | + this.containerRegistry.RegisterSingleton<IAsyncHandlerContextFactory>(factory); | |
| 21 | + } | |
| 22 | + | |
| 23 | + } | |
| 24 | +} |
| @@ -0,0 +1,25 @@ | ||
| 1 | +using CleanAuLait.Core.DI; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller.DI | |
| 5 | +{ | |
| 6 | + internal class RequestScopeGenerator : IRequestScopeGenerator | |
| 7 | + { | |
| 8 | + public IRequestScopedProvider CreateScope() | |
| 9 | + { | |
| 10 | + try | |
| 11 | + { | |
| 12 | + return new RequestScopedProvider(GetContainer().CreateScope()); | |
| 13 | + } | |
| 14 | + catch (Exception e) | |
| 15 | + { | |
| 16 | + throw new DIException(e); | |
| 17 | + } | |
| 18 | + } | |
| 19 | + | |
| 20 | + protected virtual IContainerProvider GetContainer() | |
| 21 | + { | |
| 22 | + return ContainerLocator.Container; | |
| 23 | + } | |
| 24 | + } | |
| 25 | +} |
| @@ -0,0 +1,32 @@ | ||
| 1 | +using CleanAuLait.Core.DI; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller.DI; | |
| 5 | + | |
| 6 | +internal class RequestScopedProvider : IRequestScopedProvider | |
| 7 | +{ | |
| 8 | + private readonly IScopedProvider scopedProvider; | |
| 9 | + | |
| 10 | + public RequestScopedProvider(IScopedProvider scopedProvider) | |
| 11 | + { | |
| 12 | + this.scopedProvider = scopedProvider; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public object Resolve(Type type) | |
| 16 | + { | |
| 17 | + try | |
| 18 | + { | |
| 19 | + return this.scopedProvider.Resolve(type); | |
| 20 | + } | |
| 21 | + catch (ContainerResolutionException e) | |
| 22 | + { | |
| 23 | + throw new DIException(e); | |
| 24 | + } | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void Dispose() | |
| 28 | + { | |
| 29 | + this.scopedProvider?.Dispose(); | |
| 30 | + } | |
| 31 | + | |
| 32 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,23 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Boundary.Controller; | |
| 2 | +using Prism.Ioc; | |
| 3 | + | |
| 4 | +namespace CleanAuLait.Adaptor.Controller | |
| 5 | +{ | |
| 6 | + public class HandlerContextFactoryRegistrar : | |
| 7 | + AbstractHandlerContextFactoryRegistrar<IHandlerContextFactory, HandlerContextFactory> | |
| 8 | + { | |
| 9 | + private readonly IContainerRegistry containerRegistry; | |
| 10 | + | |
| 11 | + public HandlerContextFactoryRegistrar(IContainerRegistry containerRegistry) | |
| 12 | + { | |
| 13 | + this.containerRegistry = containerRegistry; | |
| 14 | + } | |
| 15 | + | |
| 16 | + public override void Register() | |
| 17 | + { | |
| 18 | + var factory = CreateFactoryFactory(); | |
| 19 | + | |
| 20 | + this.containerRegistry.RegisterSingleton<IHandlerContextFactory>(factory); | |
| 21 | + } | |
| 22 | + } | |
| 23 | +} |
| @@ -0,0 +1,17 @@ | ||
| 1 | +<Project Sdk="Microsoft.NET.Sdk"> | |
| 2 | + | |
| 3 | + <PropertyGroup> | |
| 4 | + <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework> | |
| 5 | + <ImplicitUsings>enable</ImplicitUsings> | |
| 6 | + <Nullable>enable</Nullable> | |
| 7 | + </PropertyGroup> | |
| 8 | + | |
| 9 | + <ItemGroup> | |
| 10 | + <PackageReference Include="Prism.Core" Version="8.1.97" /> | |
| 11 | + </ItemGroup> | |
| 12 | + | |
| 13 | + <ItemGroup> | |
| 14 | + <ProjectReference Include="..\CleanAuLait\CleanAuLait.csproj" /> | |
| 15 | + </ItemGroup> | |
| 16 | + | |
| 17 | +</Project> |
| @@ -0,0 +1,36 @@ | ||
| 1 | +using CleanAuLait.Adaptor.Controller.DI; | |
| 2 | +using CleanAuLait.Core.Resource; | |
| 3 | +using NLog; | |
| 4 | +using Prism.Ioc; | |
| 5 | +using Prism.Modularity; | |
| 6 | + | |
| 7 | +namespace CleanAuLait | |
| 8 | +{ | |
| 9 | + public class CleanAuLaitPrismModule : IModule | |
| 10 | + { | |
| 11 | + private static readonly ILogger logger = LogManager.GetCurrentClassLogger(); | |
| 12 | + | |
| 13 | + public void RegisterTypes(IContainerRegistry containerRegistry) | |
| 14 | + { | |
| 15 | + // | |
| 16 | + // Request Scope | |
| 17 | + // | |
| 18 | + | |
| 19 | + containerRegistry.RegisterSingleton<IRequestScopeGenerator, RequestScopeGenerator>(); | |
| 20 | + | |
| 21 | + /// | |
| 22 | + /// Resources | |
| 23 | + /// | |
| 24 | + | |
| 25 | + containerRegistry.RegisterSingleton<ICaptionFormatter, CaptionFormatter>(); | |
| 26 | + | |
| 27 | + logger.Trace("RegisterTypes end"); | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void OnInitialized(IContainerProvider containerProvider) | |
| 31 | + { | |
| 32 | + // NOP | |
| 33 | + } | |
| 34 | + | |
| 35 | + } | |
| 36 | +} | |
| \ No newline at end of file |