• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版586504c9d8295316ca0a9f9da102c0ff136a48f7 (tree)
时间2022-05-26 19:08:06
作者yoshy <yoshy.org.bitbucket@gz.j...>
Commiteryoshy

Log Message

[MOD] ハンドラコンテキストファクトリのマップ化により複数のハンドラキューを使い分け可能な機能を実装

更改概述

差异

--- a/Adaptor/Boundary/Controller/IAsyncHandlerContextFactory.cs
+++ b/Adaptor/Boundary/Controller/IAsyncHandlerContextFactory.cs
@@ -2,8 +2,9 @@
22
33 namespace CleanAuLait48.Adaptor.Boundary.Controller
44 {
5- public interface IAsyncHandlerContextFactory
5+ public interface IAsyncHandlerContextFactory : IAttachHandlerQueueMap
66 {
7- IAsyncHandlerContext Create(IScopedComponentProvider scopedProvider);
7+ IAsyncHandlerContext Create(
8+ string handlerTypesName, IScopedComponentProvider scopedProvider);
89 }
910 }
\ No newline at end of file
--- /dev/null
+++ b/Adaptor/Boundary/Controller/IAttachHandlerQueueMap.cs
@@ -0,0 +1,13 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using System.Threading.Tasks;
6+
7+namespace CleanAuLait48.Adaptor.Boundary.Controller
8+{
9+ public interface IAttachHandlerQueueMap
10+ {
11+ IDictionary<string, IEnumerable<Type>> HandlerQueueMap { get; set; }
12+ }
13+}
--- a/Adaptor/Boundary/Controller/IHandlerContextFactory.cs
+++ b/Adaptor/Boundary/Controller/IHandlerContextFactory.cs
@@ -2,8 +2,9 @@
22
33 namespace CleanAuLait48.Adaptor.Boundary.Controller
44 {
5- public interface IHandlerContextFactory
5+ public interface IHandlerContextFactory : IAttachHandlerQueueMap
66 {
7- IHandlerContext Create(IScopedComponentProvider scopedProvider);
7+ IHandlerContext Create(
8+ string handlerTypesName, IScopedComponentProvider scopedProvider);
89 }
910 }
\ No newline at end of file
--- /dev/null
+++ b/Adaptor/Controller/AbstractHandlerContextFactoryRegistrar.cs
@@ -0,0 +1,32 @@
1+using CleanAuLait48.Adaptor.Boundary.Controller;
2+using CleanAuLait48.Core.DI;
3+using System;
4+using System.Collections.Generic;
5+
6+namespace CleanAuLait48.Adaptor.Controller
7+{
8+ public abstract class AbstractHandlerContextFactoryRegistrar<IFACTORY, FACTORY>
9+ where IFACTORY : class, IAttachHandlerQueueMap
10+ where FACTORY : IFACTORY, new()
11+ {
12+ private readonly IDictionary<string, IEnumerable<Type>> map = new Dictionary<string, IEnumerable<Type>>();
13+
14+ public void Add(string factoryName, IEnumerable<Type> handlerTypes)
15+ {
16+ map.Add(factoryName, handlerTypes);
17+ }
18+
19+ public void Register(IComponentRegistry registry)
20+ {
21+ registry.RegisterSingleton(() =>
22+ {
23+ IFACTORY factory = new FACTORY
24+ {
25+ HandlerQueueMap = map
26+ };
27+
28+ return factory;
29+ });
30+ }
31+ }
32+}
--- a/Adaptor/Controller/AsyncHandlerContextFactory.cs
+++ b/Adaptor/Controller/AsyncHandlerContextFactory.cs
@@ -2,31 +2,48 @@
22 using CleanAuLait48.Adaptor.Boundary.Controller.Handler;
33 using CleanAuLait48.Adaptor.Controller.Handler;
44 using CleanAuLait48.Core.DI;
5+using System;
56 using System.Collections.Generic;
67
78 namespace CleanAuLait48.Adaptor.Controller
89 {
910 public class AsyncHandlerContextFactory : IAsyncHandlerContextFactory
1011 {
11- private readonly IEnumerable<IAsyncRequestHandler> handlers;
12+ public IDictionary<string, IEnumerable<Type>> HandlerQueueMap { get; set; }
1213
13- public AsyncHandlerContextFactory(IEnumerable<IAsyncRequestHandler> handlers)
14+ public IAsyncHandlerContext Create(string handlerQueueName, IScopedComponentProvider scopedProvider)
1415 {
15- this.handlers = handlers;
16+ if (!HandlerQueueMap.TryGetValue(handlerQueueName, out IEnumerable<Type> handlerTypes))
17+ {
18+ throw new DIException($"Handler Queue [{handlerQueueName}] not registered.");
19+ }
20+
21+ return CreateInternal(scopedProvider, handlerTypes);
22+ }
23+
24+ protected static IAsyncHandlerContext CreateInternal(
25+ IScopedComponentProvider scopedProvider, IEnumerable<Type> handlerTypes)
26+ {
27+ Queue<IAsyncRequestHandler> queue = CreateHandlerQueue(scopedProvider, handlerTypes);
28+
29+ IAsyncHandlerContext context = new AsyncHandlerContext(queue, scopedProvider);
30+
31+ return context;
1632 }
1733
18- public IAsyncHandlerContext Create(IScopedComponentProvider scopedProvider)
34+ protected static Queue<IAsyncRequestHandler> CreateHandlerQueue(
35+ IScopedComponentProvider scopedProvider, IEnumerable<Type> handlerTypes)
1936 {
2037 Queue<IAsyncRequestHandler> queue = new Queue<IAsyncRequestHandler>();
2138
22- foreach (IAsyncRequestHandler handler in handlers)
39+ foreach (Type handlerType in handlerTypes)
2340 {
41+ IAsyncRequestHandler handler = scopedProvider.Resolve<IAsyncRequestHandler>(handlerType);
42+
2443 queue.Enqueue(handler);
2544 }
2645
27- IAsyncHandlerContext context = new AsyncHandlerContext(queue, scopedProvider);
28-
29- return context;
46+ return queue;
3047 }
3148 }
3249 }
\ No newline at end of file
--- /dev/null
+++ b/Adaptor/Controller/AsyncHandlerContextFactoryRegistrar.cs
@@ -0,0 +1,12 @@
1+using CleanAuLait48.Adaptor.Boundary.Controller;
2+using CleanAuLait48.Core.DI;
3+using System;
4+using System.Collections.Generic;
5+
6+namespace CleanAuLait48.Adaptor.Controller
7+{
8+ public class AsyncHandlerContextFactoryRegistrar :
9+ AbstractHandlerContextFactoryRegistrar<IAsyncHandlerContextFactory, AsyncHandlerContextFactory>
10+ {
11+ }
12+}
--- a/Adaptor/Controller/HandlerContextFactory.cs
+++ b/Adaptor/Controller/HandlerContextFactory.cs
@@ -2,37 +2,48 @@
22 using CleanAuLait48.Adaptor.Boundary.Controller.Handler;
33 using CleanAuLait48.Adaptor.Controller.Handler;
44 using CleanAuLait48.Core.DI;
5+using System;
56 using System.Collections.Generic;
67
78 namespace CleanAuLait48.Adaptor.Controller
89 {
910 public class HandlerContextFactory : IHandlerContextFactory
1011 {
11- private readonly IEnumerable<IRequestHandler> handlers;
12+ public IDictionary<string, IEnumerable<Type>> HandlerQueueMap { get; set; }
1213
13- public HandlerContextFactory(IEnumerable<IRequestHandler> handlers)
14+ public IHandlerContext Create(string handlerQueueName, IScopedComponentProvider scopedProvider)
1415 {
15- this.handlers = handlers;
16+ if (!HandlerQueueMap.TryGetValue(handlerQueueName, out IEnumerable<Type> handlerTypes))
17+ {
18+ throw new DIException($"Handler Queue [{handlerQueueName}] not registered.");
19+ }
20+
21+ return CreateInternal(scopedProvider, handlerTypes);
1622 }
1723
18- public IHandlerContext Create(IScopedComponentProvider scopedProvider)
24+ protected static IHandlerContext CreateInternal(
25+ IScopedComponentProvider scopedProvider, IEnumerable<Type> handlerTypes)
1926 {
20- return CreateInternal(scopedProvider, this.handlers);
27+ Queue<IRequestHandler> queue = CreateHandlerQueue(scopedProvider, handlerTypes);
28+
29+ IHandlerContext context = new HandlerContext(queue, scopedProvider);
30+
31+ return context;
2132 }
2233
23- protected static IHandlerContext CreateInternal(
24- IScopedComponentProvider scopedProvider, IEnumerable<IRequestHandler> handlers)
34+ protected static Queue<IRequestHandler> CreateHandlerQueue(
35+ IScopedComponentProvider scopedProvider, IEnumerable<Type> handlerTypes)
2536 {
2637 Queue<IRequestHandler> queue = new Queue<IRequestHandler>();
2738
28- foreach (IRequestHandler handler in handlers)
39+ foreach (Type handlerType in handlerTypes)
2940 {
41+ IRequestHandler handler = scopedProvider.Resolve<IRequestHandler>(handlerType);
42+
3043 queue.Enqueue(handler);
3144 }
3245
33- IHandlerContext context = new HandlerContext(queue, scopedProvider);
34-
35- return context;
46+ return queue;
3647 }
3748 }
3849 }
\ No newline at end of file
--- /dev/null
+++ b/Adaptor/Controller/HandlerContextFactoryRegistrar.cs
@@ -0,0 +1,12 @@
1+using CleanAuLait48.Adaptor.Boundary.Controller;
2+using CleanAuLait48.Core.DI;
3+using System;
4+using System.Collections.Generic;
5+
6+namespace CleanAuLait48.Adaptor.Controller
7+{
8+ public class HandlerContextFactoryRegistrar :
9+ AbstractHandlerContextFactoryRegistrar<IHandlerContextFactory, HandlerContextFactory>
10+ {
11+ }
12+}
--- a/Adaptor/Controller/Router/AsyncUseCaseRouter.cs
+++ b/Adaptor/Controller/Router/AsyncUseCaseRouter.cs
@@ -13,13 +13,6 @@ namespace CleanAuLait48.Adaptor.Controller.Router
1313 {
1414 private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
1515
16- private readonly IAsyncRequestScopeGenerator scopeGenerator;
17-
18- public AsyncUseCaseRouter(IAsyncRequestScopeGenerator scopeGenerator)
19- {
20- this.scopeGenerator = scopeGenerator;
21- }
22-
2316 public async Task<UseCaseResponse> HandleAsync(UseCaseRequest req, IAsyncHandlerContext context)
2417 {
2518 try
@@ -28,7 +21,6 @@ namespace CleanAuLait48.Adaptor.Controller.Router
2821
2922 IAsyncUseCaseRouterAwareInteractor asyncInteractor = GetComponent(context.ScopedProvider, req);
3023
31- // routing map is null, or request type key not registered on routing map.
3224 if (asyncInteractor == null)
3325 {
3426 logger.Error("get async interactor instance failed.");
@@ -45,7 +37,6 @@ namespace CleanAuLait48.Adaptor.Controller.Router
4537 }
4638 catch (DIException e)
4739 {
48- // component concrete instance not registered on di container.
4940 string msg = "コンポーネントがDIコンテナに登録されていません";
5041 throw new ApplicationException(msg, e);
5142 }
--- a/Adaptor/Controller/Router/UseCaseRouter.cs
+++ b/Adaptor/Controller/Router/UseCaseRouter.cs
@@ -12,13 +12,6 @@ namespace CleanAuLait48.Adaptor.Controller.Router
1212 {
1313 private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
1414
15- private readonly IRequestScopeGenerator scopeGenerator;
16-
17- public UseCaseRouter(IRequestScopeGenerator scopeGenerator)
18- {
19- this.scopeGenerator = scopeGenerator;
20- }
21-
2215 public UseCaseResponse Handle(UseCaseRequest req, IHandlerContext context)
2316 {
2417 try
--- a/CleanAuLait48.csproj
+++ b/CleanAuLait48.csproj
@@ -54,6 +54,10 @@
5454 <Reference Include="System.Xml" />
5555 </ItemGroup>
5656 <ItemGroup>
57+ <Compile Include="Adaptor\Boundary\Controller\IAttachHandlerQueueMap.cs" />
58+ <Compile Include="Adaptor\Controller\AbstractHandlerContextFactoryRegistrar.cs" />
59+ <Compile Include="Adaptor\Controller\AsyncHandlerContextFactoryRegistrar.cs" />
60+ <Compile Include="Adaptor\Controller\HandlerContextFactoryRegistrar.cs" />
5761 <Compile Include="CleanAuLait48ComponentRegisterer.cs" />
5862 <Compile Include="Adaptor\Boundary\Controller\Handler\IAsyncRequestHandler.cs" />
5963 <Compile Include="Adaptor\Boundary\Controller\Handler\IRequestHandler.cs" />
--- a/CleanAuLait48ComponentRegisterer.cs
+++ b/CleanAuLait48ComponentRegisterer.cs
@@ -34,9 +34,6 @@ namespace CleanAuLait48
3434 componentRegistry.RegisterSingleton<IRequestScopeGenerator, RequestScopeGenerator>();
3535 componentRegistry.RegisterSingleton<IAsyncRequestScopeGenerator, AsyncRequestScopeGenerator>();
3636
37- componentRegistry.RegisterSingleton<IHandlerContextFactory, HandlerContextFactory>();
38- componentRegistry.RegisterSingleton<IAsyncHandlerContextFactory, AsyncHandlerContextFactory>();
39-
4037 logger.Trace("RegisterTypes end");
4138 }
4239