Skip to main content
Table of Contents

Interface IPipelineBehavior<TRequest, TResult>

Namespace
Stratara.Abstractions.Mediator
Assembly
Stratara.Abstractions.dll

Pipeline behavior invoked around each IMediator dispatch of an IRequest<TResult>. Behaviors form a chain: each calls next to invoke the next behavior or the handler at the chain's end.

public interface IPipelineBehavior<in TRequest, TResult> where TRequest : IRequest<TResult>

Type Parameters

TRequest

The concrete request type the behavior observes.

TResult

The result type produced by the handler at the chain's end.

Extension Methods

Remarks

Behaviors run in DI registration order — the first registered behavior is the outermost wrapper, the handler is invoked innermost. A behavior may short-circuit the pipeline by returning without awaiting next, or transform the result returned from the inner pipeline. Register with services.AddPipelineBehaviorWithResult(typeof(MyBehavior<,>)).

Methods

HandleAsync(TRequest, Func<Task<TResult>>, CancellationToken)

Run the behavior around the rest of the pipeline.

Task<TResult> HandleAsync(TRequest request, Func<Task<TResult>> next, CancellationToken cancellationToken)

Parameters

request TRequest

The dispatched request instance.

next Func<Task<TResult>>

Delegate invoking the next behavior or the final handler.

cancellationToken CancellationToken

Propagated from the IMediator call site.

Returns

Task<TResult>

The result produced by the inner pipeline, possibly transformed by this behavior.