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

New Post: WebAPI 2 & Autofac

$
0
0
Well.. after doing some tests i finally got it working :D. Pls find below the changes:
# AutofacValidationModule
// Old Code
builder.RegisterType(item.ValidatorType).Keyed<IValidator>(item.InterfaceType).As<IValidator>();
//New Code
builder.RegisterType(x.ValidatorType).As(x.InterfaceType)


# AutofacValidatorFactory
// Old Code
public override IValidator CreateInstance(Type validatorType)
{
    return _Container.ResolveOptionalKeyed<IValidator>(validatorType);
}
// New Code
public override IValidator CreateInstance(Type validatorType)
{
    using (var scope = _Container.BeginLifetimeScope("AutofacWebRequest"))
    {
        return scope.IsRegistered(validatorType) ? scope.Resolve(validatorType) as IValidator : null;
    }
}

Viewing all articles
Browse latest Browse all 1917

Trending Articles



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