我需要能够提供IComponentContext
给我ValidatorFactory
解决 FluentValidation 验证器。我有点卡住了。
验证器工厂
public class ValidatorFactory : ValidatorFactoryBase
{
private readonly IComponentContext context;
public ValidatorFactory(IComponentContext context)
{
this.context = context;
}
public override IValidator CreateInstance(Type validatorType)
{
return context.Resolve(validatorType) as IValidator;
}
}
如何提供上下文并注册ValidatorFactory
FluentValidation.Mvc.FluentValidationModelValidatorProvider.Configure(x => x.ValidatorFactory = new ValidatorFactory());