• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

コミットメタ情報

リビジョン9a78b11a152465e143c6f339759b754e8b15e604 (tree)
日時2022-05-26 19:07:40
作者yoshy <yoshy.org.bitbucket@gz.j...>
コミッターyoshy

ログメッセージ

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

変更サマリ

差分

--- a/Adaptor/Boundary/Controller/IAsyncHandlerContext.cs
+++ b/Adaptor/Boundary/Controller/IAsyncHandlerContext.cs
@@ -9,7 +9,7 @@ namespace CleanAuLait.Adaptor.Boundary.Controller
99 {
1010 Queue<IAsyncRequestHandler> HandlerQueue { get; }
1111
12- IScopedProvider Scope { get; }
12+ IScopedProvider ScopedProvider { get; }
1313
1414 Task<UseCaseResponse> HandleNextAsync(UseCaseRequest req, IAsyncHandlerContext context);
1515 }
--- a/Adaptor/Boundary/Controller/IAsyncHandlerContextFactory.cs
+++ b/Adaptor/Boundary/Controller/IAsyncHandlerContextFactory.cs
@@ -2,8 +2,9 @@
22
33 namespace CleanAuLait.Adaptor.Boundary.Controller
44 {
5- public interface IAsyncHandlerContextFactory
5+ public interface IAsyncHandlerContextFactory : IAttachHandlerQueueMap
66 {
7- IAsyncHandlerContext Create(IScopedProvider scope);
7+ IAsyncHandlerContext Create(
8+ string handlerTypesName,IScopedProvider 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 CleanAuLait.Adaptor.Boundary.Controller
8+{
9+ public interface IAttachHandlerQueueMap
10+ {
11+ IDictionary<string, IEnumerable<Type>> HandlerQueueMap { get; set; }
12+ }
13+}
--- a/Adaptor/Boundary/Controller/IHandlerContext.cs
+++ b/Adaptor/Boundary/Controller/IHandlerContext.cs
@@ -9,7 +9,7 @@ namespace CleanAuLait.Adaptor.Boundary.Controller
99 {
1010 Queue<IRequestHandler> HandlerQueue { get; }
1111
12- IScopedProvider Scope { get; }
12+ IScopedProvider ScopedProvider { get; }
1313
1414 UseCaseResponse HandleNext(UseCaseRequest req, IHandlerContext context);
1515 }
--- a/Adaptor/Boundary/Controller/IHandlerContextFactory.cs
+++ b/Adaptor/Boundary/Controller/IHandlerContextFactory.cs
@@ -2,8 +2,9 @@
22
33 namespace CleanAuLait.Adaptor.Boundary.Controller
44 {
5- public interface IHandlerContextFactory
5+ public interface IHandlerContextFactory : IAttachHandlerQueueMap
66 {
7- IHandlerContext Create(IScopedProvider scope);
7+ IHandlerContext Create(
8+ string handlerTypesName, IScopedProvider scopedProvider);
89 }
910 }
\ No newline at end of file
--- /dev/null
+++ b/Adaptor/Controller/AbstractHandlerContextFactoryRegistrar.cs
@@ -0,0 +1,30 @@
1+using CleanAuLait.Adaptor.Boundary.Controller;
2+using Prism.Ioc;
3+
4+namespace CleanAuLait.Adaptor.Controller
5+{
6+ public abstract class AbstractHandlerContextFactoryRegistrar<IFACTORY, FACTORY>
7+ where IFACTORY : class, IAttachHandlerQueueMap
8+ where FACTORY : IFACTORY, new()
9+ {
10+ private readonly IDictionary<string, IEnumerable<Type>> map = new Dictionary<string, IEnumerable<Type>>();
11+
12+ public void Add(string factoryName, IEnumerable<Type> handlerTypes)
13+ {
14+ map.Add(factoryName, handlerTypes);
15+ }
16+
17+ public void Register(IContainerRegistry registry)
18+ {
19+ registry.RegisterSingleton<IFACTORY>(() =>
20+ {
21+ IFACTORY factory = new FACTORY
22+ {
23+ HandlerQueueMap = map
24+ };
25+
26+ return factory;
27+ });
28+ }
29+ }
30+}
--- a/Adaptor/Controller/AsyncHandlerContextFactory.cs
+++ b/Adaptor/Controller/AsyncHandlerContextFactory.cs
@@ -1,31 +1,48 @@
11 using CleanAuLait.Adaptor.Boundary.Controller;
22 using CleanAuLait.Adaptor.Boundary.Controller.Handler;
33 using CleanAuLait.Adaptor.Controller.Handler;
4+using CleanAuLait.Core.DI;
45 using Prism.Ioc;
56
67 namespace CleanAuLait.Adaptor.Controller
78 {
89 public class AsyncHandlerContextFactory : IAsyncHandlerContextFactory
910 {
10- private readonly IEnumerable<IAsyncRequestHandler> handlers;
11+ public IDictionary<string, IEnumerable<Type>> HandlerQueueMap { get; set; }
1112
12- public AsyncHandlerContextFactory(IEnumerable<IAsyncRequestHandler> handlers)
13+ public IAsyncHandlerContext Create(string handlerQueueName, IScopedProvider scopedProvider)
1314 {
14- this.handlers = handlers;
15+ if (!HandlerQueueMap.TryGetValue(handlerQueueName, out IEnumerable<Type> handlerTypes))
16+ {
17+ throw new DIException($"Handler Queue [{handlerQueueName}] not registered.");
18+ }
19+
20+ return CreateInternal(scopedProvider, handlerTypes);
21+ }
22+
23+ protected static IAsyncHandlerContext CreateInternal(
24+ IScopedProvider scopedProvider, IEnumerable<Type> handlerTypes)
25+ {
26+ Queue<IAsyncRequestHandler> queue = CreateHandlerQueue(scopedProvider, handlerTypes);
27+
28+ IAsyncHandlerContext context = new AsyncHandlerContext(queue, scopedProvider);
29+
30+ return context;
1531 }
1632
17- public IAsyncHandlerContext Create(IScopedProvider scope)
33+ protected static Queue<IAsyncRequestHandler> CreateHandlerQueue(
34+ IScopedProvider scopedProvider, IEnumerable<Type> handlerTypes)
1835 {
1936 Queue<IAsyncRequestHandler> queue = new();
2037
21- foreach (IAsyncRequestHandler handler in handlers)
38+ foreach (Type handlerType in handlerTypes)
2239 {
40+ IAsyncRequestHandler handler = (IAsyncRequestHandler)scopedProvider.Resolve(handlerType);
41+
2342 queue.Enqueue(handler);
2443 }
2544
26- IAsyncHandlerContext context = new AsyncHandlerContext(queue, scope);
27-
28- return context;
45+ return queue;
2946 }
3047 }
3148 }
\ No newline at end of file
--- /dev/null
+++ b/Adaptor/Controller/AsyncHandlerContextFactoryRegistrar.cs
@@ -0,0 +1,12 @@
1+using CleanAuLait.Adaptor.Boundary.Controller;
2+using CleanAuLait.Core.DI;
3+using System;
4+using System.Collections.Generic;
5+
6+namespace CleanAuLait.Adaptor.Controller
7+{
8+ public class AsyncHandlerContextFactoryRegistrar :
9+ AbstractHandlerContextFactoryRegistrar<IAsyncHandlerContextFactory, AsyncHandlerContextFactory>
10+ {
11+ }
12+}
--- a/Adaptor/Controller/Handler/AsyncHandlerContext.cs
+++ b/Adaptor/Controller/Handler/AsyncHandlerContext.cs
@@ -9,12 +9,12 @@ namespace CleanAuLait.Adaptor.Controller.Handler
99 public class AsyncHandlerContext : IAsyncHandlerContext
1010 {
1111 public Queue<IAsyncRequestHandler> HandlerQueue { get; }
12- public IScopedProvider Scope { get; }
12+ public IScopedProvider ScopedProvider { get; }
1313
14- public AsyncHandlerContext(Queue<IAsyncRequestHandler> queue, IScopedProvider scope)
14+ public AsyncHandlerContext(Queue<IAsyncRequestHandler> queue, IScopedProvider scopedProvider)
1515 {
1616 this.HandlerQueue = queue;
17- this.Scope = scope;
17+ this.ScopedProvider = scopedProvider;
1818 }
1919
2020 public async Task<UseCaseResponse> HandleNextAsync(UseCaseRequest req, IAsyncHandlerContext context)
--- a/Adaptor/Controller/Handler/HandlerContext.cs
+++ b/Adaptor/Controller/Handler/HandlerContext.cs
@@ -9,12 +9,12 @@ namespace CleanAuLait.Adaptor.Controller.Handler
99 public class HandlerContext : IHandlerContext
1010 {
1111 public Queue<IRequestHandler> HandlerQueue { get; }
12- public IScopedProvider Scope { get; }
12+ public IScopedProvider ScopedProvider { get; }
1313
14- public HandlerContext(Queue<IRequestHandler> queue, IScopedProvider scope)
14+ public HandlerContext(Queue<IRequestHandler> queue, IScopedProvider scopedProvider)
1515 {
1616 this.HandlerQueue = queue;
17- this.Scope = scope;
17+ this.ScopedProvider = scopedProvider;
1818 }
1919
2020 public UseCaseResponse HandleNext(UseCaseRequest req, IHandlerContext context)
--- a/Adaptor/Controller/HandlerContextFactory.cs
+++ b/Adaptor/Controller/HandlerContextFactory.cs
@@ -1,31 +1,48 @@
11 using CleanAuLait.Adaptor.Boundary.Controller;
22 using CleanAuLait.Adaptor.Boundary.Controller.Handler;
33 using CleanAuLait.Adaptor.Controller.Handler;
4+using CleanAuLait.Core.DI;
45 using Prism.Ioc;
56
67 namespace CleanAuLait.Adaptor.Controller
78 {
89 public class HandlerContextFactory : IHandlerContextFactory
910 {
10- private readonly IEnumerable<IRequestHandler> handlers;
11+ public IDictionary<string, IEnumerable<Type>> HandlerQueueMap { get; set; }
1112
12- public HandlerContextFactory(IEnumerable<IRequestHandler> handlers)
13+ public IHandlerContext Create(string handlerQueueName, IScopedProvider scopedProvider)
1314 {
14- this.handlers = handlers;
15+ if (!HandlerQueueMap.TryGetValue(handlerQueueName, out IEnumerable<Type> handlerTypes))
16+ {
17+ throw new DIException($"Handler Queue [{handlerQueueName}] not registered.");
18+ }
19+
20+ return CreateInternal(scopedProvider, handlerTypes);
21+ }
22+
23+ protected static IHandlerContext CreateInternal(
24+ IScopedProvider scopedProvider, IEnumerable<Type> handlerTypes)
25+ {
26+ Queue<IRequestHandler> queue = CreateHandlerQueue(scopedProvider, handlerTypes);
27+
28+ IHandlerContext context = new HandlerContext(queue, scopedProvider);
29+
30+ return context;
1531 }
1632
17- public IHandlerContext Create(IScopedProvider scope)
33+ protected static Queue<IRequestHandler> CreateHandlerQueue(
34+ IScopedProvider scopedProvider, IEnumerable<Type> handlerTypes)
1835 {
1936 Queue<IRequestHandler> queue = new();
2037
21- foreach (IRequestHandler handler in handlers)
38+ foreach (Type handlerType in handlerTypes)
2239 {
40+ IRequestHandler handler = (IRequestHandler)scopedProvider.Resolve(handlerType);
41+
2342 queue.Enqueue(handler);
2443 }
2544
26- IHandlerContext context = new HandlerContext(queue, scope);
27-
28- return context;
45+ return queue;
2946 }
3047 }
3148 }
\ No newline at end of file
--- /dev/null
+++ b/Adaptor/Controller/HandlerContextFactoryRegistrar.cs
@@ -0,0 +1,12 @@
1+using CleanAuLait.Adaptor.Boundary.Controller;
2+using CleanAuLait.Core.DI;
3+using System;
4+using System.Collections.Generic;
5+
6+namespace CleanAuLait.Adaptor.Controller
7+{
8+ public class HandlerContextFactoryRegistrar :
9+ AbstractHandlerContextFactoryRegistrar<IHandlerContextFactory, HandlerContextFactory>
10+ {
11+ }
12+}
--- a/Adaptor/Controller/Router/AbstractUseCaseRouter.cs
+++ b/Adaptor/Controller/Router/AbstractUseCaseRouter.cs
@@ -9,18 +9,11 @@ namespace CleanAuLait.Adaptor.Controller.Router
99 {
1010 private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
1111
12- protected readonly IRequestScopeGenerator scopeGenerator;
13-
14- public AbstractUseCaseRouter(IRequestScopeGenerator scopeGenerator)
15- {
16- this.scopeGenerator = scopeGenerator;
17- }
18-
19- protected T GetComponent(IScopedProvider scope, IUseCaseRouterAware req)
12+ protected T GetComponent(IScopedProvider scopedProvider, IUseCaseRouterAware req)
2013 {
2114 Type interactorType = req.GetInteractorType();
2215
23- if (!interactorType.IsAssignableTo(typeof(T)))
16+ if (!typeof(T).IsAssignableFrom(interactorType))
2417 {
2518 logger.Trace($"{interactorType.Name} not assignable to {typeof(T).Name}.)");
2619 return default;
@@ -28,7 +21,7 @@ namespace CleanAuLait.Adaptor.Controller.Router
2821
2922 try
3023 {
31- return (T)scope.Resolve(interactorType);
24+ return (T)scopedProvider.Resolve(interactorType);
3225 }
3326 catch (ContainerResolutionException e)
3427 {
--- a/Adaptor/Controller/Router/AsyncUseCaseRouter.cs
+++ b/Adaptor/Controller/Router/AsyncUseCaseRouter.cs
@@ -12,20 +12,14 @@ namespace CleanAuLait.Adaptor.Controller.Router
1212 {
1313 private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
1414
15- public AsyncUseCaseRouter(IRequestScopeGenerator scopeGenerator) : base(scopeGenerator)
16- {
17- }
18-
1915 public async Task<UseCaseResponse> HandleAsync(UseCaseRequest req, IAsyncHandlerContext context)
2016 {
2117 try
2218 {
23- using IScopedProvider scope = scopeGenerator.CreateScope();
2419 logger.Trace($"-> ASYNC REQUEST = {req}");
2520
26- IAsyncUseCaseRouterAwareInteractor asyncInteractor = GetComponent(scope, req);
21+ IAsyncUseCaseRouterAwareInteractor asyncInteractor = GetComponent(context.ScopedProvider, req);
2722
28- // routing map is null, or request type key not registered on routing map.
2923 if (asyncInteractor == null)
3024 {
3125 logger.Error("get async interactor instance failed.");
@@ -42,7 +36,6 @@ namespace CleanAuLait.Adaptor.Controller.Router
4236 }
4337 catch (DIException e)
4438 {
45- // component concrete instance not registered on di container.
4639 string msg = "コンポーネントがDIコンテナに登録されていません";
4740 throw new ApplicationException(msg, e);
4841 }
--- a/Adaptor/Controller/Router/UseCaseRouter.cs
+++ b/Adaptor/Controller/Router/UseCaseRouter.cs
@@ -12,20 +12,14 @@ namespace CleanAuLait.Adaptor.Controller.Router
1212 {
1313 private static readonly ILogger logger = LogManager.GetCurrentClassLogger();
1414
15- public UseCaseRouter(IRequestScopeGenerator scopeGenerator) : base(scopeGenerator)
16- {
17- }
18-
1915 public UseCaseResponse Handle(UseCaseRequest req, IHandlerContext context)
2016 {
2117 try
2218 {
23- using IScopedProvider scope = scopeGenerator.CreateScope();
2419 logger.Trace($"-> REQUEST = {req}");
2520
26- IUseCaseRouterAwareInteractor interactor = GetComponent(scope, req);
21+ IUseCaseRouterAwareInteractor interactor = GetComponent(context.ScopedProvider, req);
2722
28- // routing map is null, or request type key not registered on routing map.
2923 if (interactor == null)
3024 {
3125 logger.Error("get interactor instance failed.");
@@ -42,7 +36,6 @@ namespace CleanAuLait.Adaptor.Controller.Router
4236 }
4337 catch (DIException e)
4438 {
45- // component concrete instance not registered on di container.
4639 string msg = $"コンポーネントがDIコンテナに登録されていません:{e}";
4740 throw new ApplicationException(msg, e);
4841 }
--- a/CleanAuLaitModule.cs
+++ b/CleanAuLaitModule.cs
@@ -24,9 +24,6 @@ namespace CleanAuLait
2424
2525 containerRegistry.RegisterSingleton<IRequestScopeGenerator, RequestScopeGenerator>();
2626
27- containerRegistry.RegisterSingleton<IHandlerContextFactory, HandlerContextFactory>();
28- containerRegistry.RegisterSingleton<IAsyncHandlerContextFactory, AsyncHandlerContextFactory>();
29-
3027 ///
3128 /// Resources
3229 ///