Class AotFluentValidatorResolver
- Namespace
- Excalibur.Dispatch.Validation.FluentValidation
- Assembly
- Excalibur.Dispatch.Validation.FluentValidation.dll
AOT-compatible FluentValidation validator resolver that uses compile-time code generation.
public sealed class AotFluentValidatorResolver : IValidatorResolver
- Inheritance
-
AotFluentValidatorResolver
- Implements
- Inherited Members
- Extension Methods
Remarks
This implementation avoids reflection by delegating to a source-generated IAotValidationDispatcher that maps each message type to its strongly-typed validators at compile time.
If no IAotValidationDispatcher is registered in the service provider,
TryValidateAsync(IDispatchMessage, IServiceProvider?, CancellationToken) throws InvalidOperationException directing
the consumer to add the Excalibur.Dispatch.SourceGenerators analyzer package.
Constructors
AotFluentValidatorResolver(IServiceProvider)
AOT-compatible FluentValidation validator resolver that uses compile-time code generation.
public AotFluentValidatorResolver(IServiceProvider provider)
Parameters
providerIServiceProviderThe service provider for dependency injection.
Remarks
This implementation avoids reflection by delegating to a source-generated IAotValidationDispatcher that maps each message type to its strongly-typed validators at compile time.
If no IAotValidationDispatcher is registered in the service provider,
TryValidateAsync(IDispatchMessage, IServiceProvider?, CancellationToken) throws InvalidOperationException directing
the consumer to add the Excalibur.Dispatch.SourceGenerators analyzer package.
Methods
TryValidateAsync(IDispatchMessage, IServiceProvider?, CancellationToken)
Validates a message using AOT-compatible, source-generated dispatch logic.
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>
Validation result if validators exist, null otherwise.
Exceptions
- InvalidOperationException
Thrown when no IAotValidationDispatcher is registered. This means the
Excalibur.Dispatch.SourceGeneratorspackage is not referenced as an analyzer, or no FluentValidation validators forIDispatchMessagetypes were discovered at compile time.