Trying to use a simple AbstractValidator derrived class:
The code I used for registration was:
So, I decided to update that. To my happiness, the above DI issues (declaring a new abstractvalidator) went away.
So, here is the code to register all your validators in the latest Autofac should anyone need it.
public abstract class EnhancedValidator<T> : AbstractValidator<T>
{
}
Just the act of declaring the above class cause the DI to crash with EnhancedValidator1[T] is not assignable to FluentValidation.IValidator
1.The code I used for registration was:
AssemblyScanner findValidatorsInAssembly = AssemblyScanner.FindValidatorsInAssembly(typeof(MvcApplication).Assembly);
foreach (AssemblyScanner.AssemblyScanResult item in findValidatorsInAssembly)
{
builder.RegisterType(item.ValidatorType).As(item.InterfaceType);
}
As far as the DI registration goes...I was using the code from many years ago in my own thread on these forums. Autofac has been enhanced a bunch.So, I decided to update that. To my happiness, the above DI issues (declaring a new abstractvalidator) went away.
So, here is the code to register all your validators in the latest Autofac should anyone need it.
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.AsClosedTypesOf(typeof(IValidator<>)).AsImplementedInterfaces()
.InstancePerLifetimeScope();
Simple huh!?