Beispiel #1
0
        public Task <TResult> ProcessAsync <TResult>(IQuery <TResult> query, CancellationToken cancellationToken)
        {
            var handlerType = typeof(IQueryHandler <,>).MakeGenericType(query.GetType(), typeof(TResult));

            try
            {
                var handler = _container.GetInstance(handlerType);
                var method  = handlerType.GetMethod(nameof(IQueryHandler <IQuery <TResult>, TResult> .HandleAsync));
                return((Task <TResult>)method.Invoke(handler, new object[] { query, cancellationToken }));
            }
            catch (ActivationException exception)
            {
                throw new UnresolvedHandlerException(
                          StringResources.CannotResolveHandler(handlerType),
                          exception);
            }
            catch (TargetInvocationException exception)
            {
                throw exception.InnerException;
            }
        }
Beispiel #2
0
        public Task ProcessAsync(ICommand command, CancellationToken cancellationToken)
        {
            var handlerType = typeof(ICommandHandler <>).MakeGenericType(command.GetType());

            try
            {
                var handler = _container.GetInstance(handlerType);
                var method  = handlerType.GetMethod(nameof(ICommandHandler <ICommand> .HandleAsync));
                return((Task)method.Invoke(handler, new object[] { command, cancellationToken }));
            }
            catch (ActivationException exception)
            {
                throw new UnresolvedHandlerException(
                          StringResources.CannotResolveHandler(handlerType),
                          exception);
            }
            catch (TargetInvocationException exception)
            {
                throw exception.InnerException;
            }
        }