public async Task DecorateAsync(TCommand command, IOperationHandler <TCommand> handler, CancellationToken cancellationToken) { await _writer.WriteLineAsync($"Preprocess command `{typeof(TCommand).Name}` by `{GetType().Name}`"); await handler.HandleAsync(command, cancellationToken); await _writer.WriteLineAsync($"Postprocess command `{typeof(TCommand).Name}` by `{GetType().Name}`"); }
public override async Task <TResult> DecorateAsync(TCommand command, IOperationHandler <TCommand, TResult> handler, CancellationToken cancellationToken) { await _writer.WriteLineAsync($"Preprocess command `{typeof(TCommand).Name}` by `{GetType().Name}`"); var result = await handler.HandleAsync(command, cancellationToken); await _writer.WriteLineAsync($"Postprocess command `{typeof(TCommand).Name}` by `{GetType().Name}`"); return(result); }
public async Task <TResult> DecorateAsync(TQuery query, IOperationHandler <TQuery, TResult> handler, CancellationToken cancellationToken) { await _writer.WriteLineAsync($"Preprocess query `{typeof(TQuery).Name}` by `{GetType().Name}`"); var result = await handler.HandleAsync(query, cancellationToken); await _writer.WriteLineAsync($"Postprocess query `{typeof(TQuery).Name}` by `{GetType().Name}`"); return(result); }
public Task <TResult> HandleAsync(TOperation operation, CancellationToken cancellationToken) { if (operation is ICommand <TResult> ) { return(((BaseOperationDecorator <TOperation, TResult>)_serviceProvider.GetService(typeof(ICommandDecorator <,>).MakeGenericType(operation.GetType(), typeof(TResult)))) .DecorateAsync(operation, _handler, cancellationToken)); } else if (operation is IQuery <TResult> ) { return(((BaseOperationDecorator <TOperation, TResult>)_serviceProvider.GetService(typeof(IQueryDecorator <,>).MakeGenericType(operation.GetType(), typeof(TResult)))) .DecorateAsync(operation, _handler, cancellationToken)); } else { return(_handler.HandleAsync(operation, cancellationToken)); } }
public Task <TOutput> ExecuteAsync <TInput, TOutput>(TInput request) { IOperationHandler <TInput, TOutput> handler = dependencyProvider.Resolve <IOperationHandler <TInput, TOutput> >(); return(handler.HandleAsync(request)); }