コード例 #1
0
        private async Task <TResponse> DoRequestAsync <TRequest, TResponse>(IDomainRequest <TRequest, TResponse> request, ILifetimeScope lifetimeScope)
            where TRequest : IDomainRequest <TRequest, TResponse>
            where TResponse : IDomainResponse
        {
            var foundHandlers = GetRequestHandlers(request.GetType()).ToList();

            if (foundHandlers.Any())
            {
                foreach (var handler in foundHandlers)
                {
                    var response = ExecuteRequestHandler(request, handler, lifetimeScope);
                    if (response != null)
                    {
                        return(response);
                    }
                }
            }

            foundHandlers = GetAsyncEventHandlers(request.GetType()).ToList();
            if (foundHandlers.Any())
            {
                foreach (var handler in foundHandlers)
                {
                    var response = await ExecuteRequestHandlerAsync(request, handler, lifetimeScope).ConfigureAwait(continueOnCapturedContext: false);

                    if (response != null)
                    {
                        return(response);
                    }
                }
            }

            return(default(TResponse));
        }
コード例 #2
0
        public async Task <IEnumerable <TResponse> > DoMulticastRequestAsync <TRequest, TResponse>(IDomainRequest <TRequest, TResponse> request, ILifetimeScope lifetimeScope)
            where TRequest : IDomainRequest <TRequest, TResponse>
            where TResponse : IDomainResponse
        {
            var responses     = new List <TResponse>();
            var foundHandlers = GetRequestHandlers(request.GetType()).ToList();

            if (foundHandlers.Any())
            {
                foreach (var handler in foundHandlers)
                {
                    var response = ExecuteRequestHandler(request, handler, lifetimeScope);
                    if (response != null)
                    {
                        responses.Add(response);
                    }
                }
            }

            foundHandlers = GetAsyncEventHandlers(request.GetType()).ToList();
            if (foundHandlers.Any())
            {
                foreach (var handler in foundHandlers)
                {
                    var response = await ExecuteRequestHandlerAsync(request, handler, lifetimeScope).ConfigureAwait(continueOnCapturedContext: false);

                    if (response != null)
                    {
                        responses.Add(response);
                    }
                }
            }

            return(responses);
        }
コード例 #3
0
 public static IDomainResponse Dispatch(IDomainRequest request)
 {
     return(_Handlers[request.GetType()](request));
 }
コード例 #4
0
 public static T Dispatch <T>(IDomainRequest request) where T : IDomainResponse
 {
     return((T)_Handlers[request.GetType()](request));
 }