Table of Contents

Class ContextValidationMiddleware

Namespace
Excalibur.Dispatch.Validation.Context
Assembly
Excalibur.Dispatch.dll

Middleware that validates message context integrity to detect data loss or corruption during processing.

public sealed class ContextValidationMiddleware : IDispatchMiddleware
Inheritance
ContextValidationMiddleware
Implements
Inherited Members
Extension Methods

Remarks

This middleware runs early in the pipeline to catch context issues before they cause downstream problems. It validates required fields, checks for corruption, and tracks metrics on validation failures.

Constructors

ContextValidationMiddleware(IContextValidator, ILogger<ContextValidationMiddleware>, IOptions<ContextValidationOptions>, IEnumerable<IContextValidator>?)

Middleware that validates message context integrity to detect data loss or corruption during processing.

public ContextValidationMiddleware(IContextValidator contextValidator, ILogger<ContextValidationMiddleware> logger, IOptions<ContextValidationOptions> options, IEnumerable<IContextValidator>? customValidators = null)

Parameters

contextValidator IContextValidator

The primary context validator.

logger ILogger<ContextValidationMiddleware>

The logger for diagnostic output.

options IOptions<ContextValidationOptions>

Configuration options for the middleware.

customValidators IEnumerable<IContextValidator>

Optional collection of custom validators.

Remarks

This middleware runs early in the pipeline to catch context issues before they cause downstream problems. It validates required fields, checks for corruption, and tracks metrics on validation failures.

Properties

Stage

Gets the stage at which this middleware runs in the pipeline.

public DispatchMiddlewareStage? Stage { get; }

Property Value

DispatchMiddlewareStage?

The current Stage value.

Remarks

Runs at PreProcessing stage (100) to catch context issues early.

Methods

InvokeAsync(IDispatchMessage, IMessageContext, DispatchRequestDelegate, CancellationToken)

Invokes the context validation middleware.

public ValueTask<IMessageResult> InvokeAsync(IDispatchMessage message, IMessageContext context, DispatchRequestDelegate nextDelegate, CancellationToken cancellationToken)

Parameters

message IDispatchMessage

The message being processed.

context IMessageContext

The message context to validate.

nextDelegate DispatchRequestDelegate

The next delegate in the pipeline.

cancellationToken CancellationToken

Cancellation token for the operation.

Returns

ValueTask<IMessageResult>

The result of message processing.