Table of Contents

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

TCommand

Command type being observed.

TResponse

Response 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

failureDetector IFunctionalFailureDetector

Detector 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

request TCommand

Request being processed.

context IRequestContext

Ambient context with correlation ID, user info, tenant info, etc.

nextStep RequestHandlerCallback<TResponse>

Callback to the next behavior or handler.

cancellationToken CancellationToken

Token to cancel the flow.

Returns

ValueTask<Either<MediatorError, TResponse>>

Final result or the modified response from the behavior.