Table of Contents

Class CommandMetricsPipelineBehavior<TCommand, TResponse>

Namespace
SimpleMediator
Assembly
SimpleMediator.dll

Records duration and outcome metrics for mediator commands.

public sealed class CommandMetricsPipelineBehavior<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
CommandMetricsPipelineBehavior<TCommand, TResponse>
Implements
ICommandPipelineBehavior<TCommand, TResponse>
IPipelineBehavior<TCommand, TResponse>
Inherited Members

Examples

services.AddSingleton<IMediatorMetrics, MeterMediatorMetrics>();
services.AddSimpleMediator(cfg => cfg.AddPipelineBehavior(typeof(CommandMetricsPipelineBehavior<,>)), assemblies);

Remarks

Uses IMediatorMetrics to expose success/failure counters and a duration histogram. The failure detector identifies functional errors without exceptions.

Constructors

CommandMetricsPipelineBehavior(IMediatorMetrics, IFunctionalFailureDetector)

Records duration and outcome metrics for mediator commands.

public CommandMetricsPipelineBehavior(IMediatorMetrics metrics, IFunctionalFailureDetector failureDetector)

Parameters

metrics IMediatorMetrics
failureDetector IFunctionalFailureDetector

Examples

services.AddSingleton<IMediatorMetrics, MeterMediatorMetrics>();
services.AddSimpleMediator(cfg => cfg.AddPipelineBehavior(typeof(CommandMetricsPipelineBehavior<,>)), assemblies);

Remarks

Uses IMediatorMetrics to expose success/failure counters and a duration histogram. The failure detector identifies functional errors without exceptions.

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.