public RequestHandlerChainer( IRequestHandlerChain <TRequest, TResponse> requestHandlerChain, IRequestHandler <TRequest, TResponse> next) { this._RequestHandlerChain = requestHandlerChain ?? throw new ArgumentNullException(nameof(requestHandlerChain)); this._Next = next ?? throw new ArgumentNullException(nameof(next)); }
public IRootRequestHandler <TResponse> GetRootRequestHandler <TRequest, TResponse>() where TRequest : IRequest <TResponse> { IRequestHandler <TRequest, TResponse> requestHandler; IEnumerable <IRequestHandlerChain <TRequest, TResponse> >?requestHandlerChains; try { requestHandler = this._RequestHandlerFactory.CreateRequestHandler <IRequestHandler <TRequest, TResponse> >(); } catch (Exception error) { throw new InvalidOperationException($"Error constructing handler for request of type {typeof(IRequestHandler<TRequest, TResponse>)}.", error); } if (requestHandler == null) { throw new InvalidOperationException($"Handler was not found for request of type {typeof(IRequestHandler<TRequest, TResponse>)}."); } try { requestHandlerChains = this._RequestHandlerFactory.CreateRequestHandlerChains <IRequestHandlerChain <TRequest, TResponse> >(); } catch (Exception error) { throw new InvalidOperationException($"Error constructing handler for request of type {typeof(IRequestHandlerChain<TRequest, TResponse>)}.", error); } //var lstRequestHandleCfg = new List<RequestHandlerConfiguration>(); var result = requestHandler; if (requestHandlerChains is object) { var lstRequestHandlerChain = requestHandlerChains.ToList(); lstRequestHandlerChain.Sort(IRequestHandlerChainBaseComparer.GetInstance()); for (int idx = lstRequestHandlerChain.Count - 1; idx >= 0; idx--) { IRequestHandlerChain <TRequest, TResponse>?chain = lstRequestHandlerChain[idx]; if (chain is object) { result = new RequestHandlerChainer <TRequest, TResponse>(chain, result); } } } return(new RootRequestHandler <TRequest, TResponse>(result)); }