FluentValidation Ninject integration
To use follow these steps:
- Wire up Asp.net MVC to use the NinjectValidatorFactory:
NinjectValidatorFactory ninjectValidatorFactory = new NinjectValidatorFactory(ninjectKernel);
ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(ninjectValidatorFactory));
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
- Add a module to your project that will bind all of your validators:
public class FluentValidatorModule : NinjectModule
{
public override void Load()
{
AssemblyScanner.FindValidatorsInAssemblyContaining<UserValidator>()
.ForEach(match => Bind(match.InterfaceType).To(match.ValidatorType));
}
}