예제 #1
0
        public Task <TResponse> Send <TResponse>(IReadStoreRequest <TResponse> request, CancellationToken cancellationToken = default)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var requestType = request.GetType();

            var handler = (RequestHandler <TResponse>)RequestHandlers.GetOrAdd(requestType, t =>
            {
                var responseType             = typeof(TResponse);
                var handlerOpenGenericType   = typeof(RequestHandler <,>);
                var handlerClosedGenericType = handlerOpenGenericType.MakeGenericType(requestType, responseType);
                var handlerInstance          = Activator.CreateInstance(handlerClosedGenericType);

                return(handlerInstance);
            });

            return(handler.Handle(request, cancellationToken, _serviceFactory));
        }
예제 #2
0
 public abstract Task <TResponse> Handle(IReadStoreRequest <TResponse> request, CancellationToken cancellationToken, ReadStoreServiceFactory serviceFactory);