Class FluentValidationMessageValidatorAdapter<TMessage>
- Namespace
- Trellis.FluentValidation
- Assembly
- Trellis.FluentValidation.dll
Adapts FluentValidation FluentValidation.IValidator<T> implementations into the Trellis
Mediator validation stage. Resolves every IValidator<TMessage> registered in DI,
runs them, and returns an aggregated Error.UnprocessableContent failure when
any validator reports errors.
public sealed class FluentValidationMessageValidatorAdapter<TMessage> : IMessageValidator<TMessage> where TMessage : IMessage
Type Parameters
TMessageThe message type the contained validators target.
- Inheritance
-
FluentValidationMessageValidatorAdapter<TMessage>
- Implements
-
IMessageValidator<TMessage>
- Inherited Members
- Extension Methods
Remarks
Registered as an open-generic IMessageValidator<TMessage> by
AddTrellisFluentValidation(IServiceCollection).
When no FluentValidation.IValidator<T> is registered for a given TMessage,
the injected sequence is empty and the adapter returns success without allocating violations.
FluentValidation property names that include member chains (Address.PostCode) or
indexers (Items[0].Sku) are translated to RFC 6901 JSON Pointers
(/Address/PostCode, /Items/0/Sku) so they round-trip correctly through
InputPointer.
Constructors
FluentValidationMessageValidatorAdapter(IEnumerable<IValidator<TMessage>>)
Adapts FluentValidation FluentValidation.IValidator<T> implementations into the Trellis
Mediator validation stage. Resolves every IValidator<TMessage> registered in DI,
runs them, and returns an aggregated Error.UnprocessableContent failure when
any validator reports errors.
public FluentValidationMessageValidatorAdapter(IEnumerable<IValidator<TMessage>> validators)
Parameters
validatorsIEnumerable<IValidator<TMessage>>
Remarks
Registered as an open-generic IMessageValidator<TMessage> by
AddTrellisFluentValidation(IServiceCollection).
When no FluentValidation.IValidator<T> is registered for a given TMessage,
the injected sequence is empty and the adapter returns success without allocating violations.
FluentValidation property names that include member chains (Address.PostCode) or
indexers (Items[0].Sku) are translated to RFC 6901 JSON Pointers
(/Address/PostCode, /Items/0/Sku) so they round-trip correctly through
InputPointer.
Methods
ValidateAsync(TMessage, CancellationToken)
Validates the message asynchronously.
public ValueTask<IResult> ValidateAsync(TMessage message, CancellationToken cancellationToken)
Parameters
messageTMessageThe message to validate.
cancellationTokenCancellationTokenA token to observe for cancellation.
Returns
- ValueTask<IResult>
Result.Ok()on success, or a failure IResult describing the violations. Field-level violations should be wrapped in an Error.UnprocessableContent so the pipeline can aggregate them across multiple validators.