Class QueryMetricsPipelineBehavior<TQuery, TResponse>
- Namespace
- SimpleMediator
- Assembly
- SimpleMediator.dll
Records duration and outcome metrics for mediator queries.
public sealed class QueryMetricsPipelineBehavior<TQuery, TResponse> : IQueryPipelineBehavior<TQuery, TResponse>, IPipelineBehavior<TQuery, TResponse> where TQuery : IQuery<TResponse>
Type Parameters
TQueryQuery type being observed.
TResponseResponse type returned by the handler.
- Inheritance
-
QueryMetricsPipelineBehavior<TQuery, TResponse>
- Implements
-
IQueryPipelineBehavior<TQuery, TResponse>IPipelineBehavior<TQuery, TResponse>
- Inherited Members
Examples
services.AddSingleton<IMediatorMetrics, MeterMediatorMetrics>();
services.AddSimpleMediator(cfg => cfg.AddPipelineBehavior(typeof(QueryMetricsPipelineBehavior<,>)), assemblies);
Remarks
Complements CommandMetricsPipelineBehavior<TCommand, TResponse> by exposing visibility into reads, including functional failures.
Constructors
QueryMetricsPipelineBehavior(IMediatorMetrics, IFunctionalFailureDetector)
Records duration and outcome metrics for mediator queries.
public QueryMetricsPipelineBehavior(IMediatorMetrics metrics, IFunctionalFailureDetector failureDetector)
Parameters
metricsIMediatorMetricsfailureDetectorIFunctionalFailureDetector
Examples
services.AddSingleton<IMediatorMetrics, MeterMediatorMetrics>();
services.AddSimpleMediator(cfg => cfg.AddPipelineBehavior(typeof(QueryMetricsPipelineBehavior<,>)), assemblies);
Remarks
Complements CommandMetricsPipelineBehavior<TCommand, TResponse> by exposing visibility into reads, including functional failures.
Methods
Handle(TQuery, IRequestContext, RequestHandlerCallback<TResponse>, CancellationToken)
Executes the behavior logic around the next pipeline element.
public ValueTask<Either<MediatorError, TResponse>> Handle(TQuery request, IRequestContext context, RequestHandlerCallback<TResponse> nextStep, CancellationToken cancellationToken)
Parameters
requestTQueryRequest 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.