Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: IValidator additional property

$
0
0
Trying to use a simple AbstractValidator derrived class:
    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.IValidator1.
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!?

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>