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
TCommandCommand type being observed.
TResponseResponse 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
metricsIMediatorMetricsfailureDetectorIFunctionalFailureDetector
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
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.