Class CommandActivityPipelineBehavior<TCommand, TResponse>
- Namespace
- SimpleMediator
- Assembly
- SimpleMediator.dll
Creates diagnostic activities for commands and annotates functional failures.
public sealed class CommandActivityPipelineBehavior<TCommand, TResponse> : ICommandPipelineBehavior<TCommand, TResponse>, IPipelineBehavior<TCommand, TResponse> where TCommand : ICommand<TResponse>
Type Parameters
TCommandCommand type being observed.
TResponseResponse type returned by the handler.
- Inheritance
-
CommandActivityPipelineBehavior<TCommand, TResponse>
- Implements
-
ICommandPipelineBehavior<TCommand, TResponse>IPipelineBehavior<TCommand, TResponse>
- Inherited Members
Examples
services.AddSingleton<IFunctionalFailureDetector, ApplicationFunctionalFailureDetector>();
services.AddSimpleMediator(cfg =>
{
cfg.AddPipelineBehavior(typeof(CommandActivityPipelineBehavior<,>));
}, typeof(CreateReservation).Assembly);
Remarks
Leverages IFunctionalFailureDetector to tag errors without depending on concrete
domain types. Activities are emitted with the SimpleMediator source ready for
OpenTelemetry.
Constructors
CommandActivityPipelineBehavior(IFunctionalFailureDetector)
Creates diagnostic activities for commands and annotates functional failures.
public CommandActivityPipelineBehavior(IFunctionalFailureDetector failureDetector)
Parameters
failureDetectorIFunctionalFailureDetectorDetector that interprets handler responses.
Examples
services.AddSingleton<IFunctionalFailureDetector, ApplicationFunctionalFailureDetector>();
services.AddSimpleMediator(cfg =>
{
cfg.AddPipelineBehavior(typeof(CommandActivityPipelineBehavior<,>));
}, typeof(CreateReservation).Assembly);
Remarks
Leverages IFunctionalFailureDetector to tag errors without depending on concrete
domain types. Activities are emitted with the SimpleMediator source ready for
OpenTelemetry.
Methods
Handle(TCommand, IRequestContext, RequestHandlerCallback<TResponse>, CancellationToken)
Executes the behavior logic around the next pipeline element.
public ValueTask<Either<MediatorError, TResponse>> Handle(TCommand request, IRequestContext context, RequestHandlerCallback<TResponse> nextStep, CancellationToken cancellationToken)
Parameters
requestTCommandRequest being processed.
contextIRequestContextAmbient context with correlation ID, user info, tenant info, etc.
nextStepRequestHandlerCallback<TResponse>Callback to the next behavior or handler.
cancellationTokenCancellationTokenToken to cancel the flow.
Returns
- ValueTask<Either<MediatorError, TResponse>>
Final result or the modified response from the behavior.