Skip to content

ValidatorFactory

Implements FluentValidation's IValidatorFactory on top of an Autofac IComponentContext, resolving IValidator<T> instances from the DI container by type rather than requiring callers to know the concrete validator implementation.

Purpose

  • Resolves the registered FluentValidation IValidator for a runtime Type or generic type parameter, delegating to the Autofac container.

Context

  • Namespace: SAIF.Services.Utilities
  • Assembly/package: SAIF.Services (packaged inside the SAIF.SAIFCode.Core NuGet package)

Public members

Member Signature Purpose
ValidatorFactory(...) public ValidatorFactory(IComponentContext componentContext) Stores the Autofac component context used to resolve validators.
GetValidator(type) public IValidator GetValidator(Type type) Resolves and returns the IValidator<type> registered in the Autofac container for the given runtime type, as a non-generic IValidator.
GetValidator<T>() public IValidator<T> GetValidator<T>() Resolves and returns the IValidator<T> registered in the Autofac container for T.

Behavioral notes

  • GetValidator(Type) builds the closed generic IValidator<> type at runtime via reflection (MakeGenericType) before resolving it from Autofac.

Sources

  • Services/SAIF.Services/Utilities/ValidatorFactory.cs