Table of Contents

Class ValidationPipelineExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Excalibur.Dispatch.dll

Extension methods for adding validation middleware to the dispatch pipeline.

public static class ValidationPipelineExtensions
Inheritance
ValidationPipelineExtensions
Inherited Members

Methods

UseValidationMiddleware(IDispatchBuilder)

Adds the validation middleware only to the dispatch pipeline, without registering any validator infrastructure.

public static IDispatchBuilder UseValidationMiddleware(this IDispatchBuilder builder)

Parameters

builder IDispatchBuilder

The dispatch builder.

Returns

IDispatchBuilder

The builder for fluent configuration.

Remarks

Precondition (loud): this method adds ValidationMiddleware but does not register the validator resolver or any IValidator<T>. If no validator infrastructure is registered, the middleware has nothing to run and messages pass through unvalidated. Use this overload only when you are wiring validator infrastructure yourself (e.g. services.AddDispatchValidation() plus your own IValidator<T> registrations).

For the batteries-included path that registers the validator infrastructure and the middleware in one call, use UseValidation(IDispatchBuilder).

The validation middleware runs registered IValidator<T> implementations against the incoming message before passing it to downstream handlers. If validation fails, a ValidationException is thrown.

Recommended pipeline order:

builder.UseExceptionMapping()
       .UseValidationMiddleware() // Validate early, before authorization (validators registered separately)
       .UseAuthorization()
       .UseRetry();