Table of Contents

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

TQuery

Query type being observed.

TResponse

Response 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

metrics IMediatorMetrics
failureDetector IFunctionalFailureDetector

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

request TQuery

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.