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

New Post: AutoFac IoC validators Issue

$
0
0
An update - Welcome to new features from Autofac....

Here is how you register all your validators:
  builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
               .AsClosedTypesOf(typeof(IValidator<>)).AsImplementedInterfaces()
               .InstancePerLifetimeScope();
The factory remains the same...
    public class ModelValidatorFactory : IValidatorFactory
    {
        public IValidator GetValidator(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            return DependencyResolver.Current.GetService(typeof(IValidator<>).MakeGenericType(type)) as IValidator;
        }

        public IValidator<T> GetValidator<T>()
        {
            return DependencyResolver.Current.GetService<IValidator<T>>();
        }
    }

Viewing all articles
Browse latest Browse all 1917

Trending Articles