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; } }
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; } }