Class FluentValidatorResolver
- Namespace
- Excalibur.Dispatch.Validation.FluentValidation
- Assembly
- Excalibur.Dispatch.Validation.FluentValidation.dll
Resolves and executes FluentValidation validators for dispatch messages.
public sealed class FluentValidatorResolver : IValidatorResolver
- Inheritance
-
FluentValidatorResolver
- Implements
- Inherited Members
- Extension Methods
Remarks
This implementation uses the non-generic IValidator interface to avoid reflection in message type resolution, though it still requires generic type creation at runtime. For full AOT support, use AotFluentValidatorResolver with source-generated validators.
The generic IValidator{T} type resolution is cached per message type to avoid repeated MakeGenericType calls on the hot path.
Constructors
FluentValidatorResolver(IServiceProvider)
Resolves and executes FluentValidation validators for dispatch messages.
public FluentValidatorResolver(IServiceProvider provider)
Parameters
providerIServiceProviderThe service provider used to resolve validators.
Remarks
This implementation uses the non-generic IValidator interface to avoid reflection in message type resolution, though it still requires generic type creation at runtime. For full AOT support, use AotFluentValidatorResolver with source-generated validators.
The generic IValidator{T} type resolution is cached per message type to avoid repeated MakeGenericType calls on the hot path.
Methods
TryValidateAsync(IDispatchMessage, IServiceProvider?, CancellationToken)
Attempts to validate the given message using registered FluentValidation validators.
[UnconditionalSuppressMessage("AOT", "IL2060:Call to 'System.Type.MakeGenericType(params Type[])' can not be statically analyzed", Justification = "FluentValidation requires runtime generic type creation. Message types are preserved via source generation.")]
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.", Justification = "FluentValidation requires dynamic code. Consider migrating to source-generated validators for full AOT support.")]
public ValueTask<IValidationResult?> TryValidateAsync(IDispatchMessage message, IServiceProvider? requestServices = null, CancellationToken cancellationToken = default)
Parameters
messageIDispatchMessageThe message to validate.
requestServicesIServiceProviderThe caller-owned request-scoped provider.
cancellationTokenCancellationTokenCancellation of validation.
Returns
- ValueTask<IValidationResult>
A validation result if validators exist; otherwise, null.