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
contextValidatorIContextValidatorThe primary context validator.
loggerILogger<ContextValidationMiddleware>The logger for diagnostic output.
optionsIOptions<ContextValidationOptions>Configuration options for the middleware.
customValidatorsIEnumerable<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
messageIDispatchMessageThe message being processed.
contextIMessageContextThe message context to validate.
nextDelegateDispatchRequestDelegateThe next delegate in the pipeline.
cancellationTokenCancellationTokenCancellation token for the operation.
Returns
- ValueTask<IMessageResult>
The result of message processing.