コード例 #1
0
ファイル: CommandDecorator.cs プロジェクト: monankov/Structr
        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}`");
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: QueryDecorator.cs プロジェクト: monankov/Structr
        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);
        }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
        public Task <TOutput> ExecuteAsync <TInput, TOutput>(TInput request)
        {
            IOperationHandler <TInput, TOutput> handler = dependencyProvider.Resolve <IOperationHandler <TInput, TOutput> >();

            return(handler.HandleAsync(request));
        }