我一直在 ASP.NET MVC 3 中的视图模型上使用 FluentValidation,效果非常好!
我现在想将它用作我的服务层内我的域对象的验证引擎。
你能用它做复杂的验证方案吗?
我正在寻找这样的东西:
public class MyService : IMyService
{
private readonly ISomeOtherService someOtherService;
public MyService(ISomeOtherService someOtherService)
{
this.someOtherService = someOtherService;
}
public bool SaveObject()
{
var validator = new MyValidator(someOtherService);
if (!validator.IsValid())
{
//spin through the validation results, add them to IValidationDictionary which is a ModelState wrapper
return false;
}
}
}
public class MyValidator : AbstractValidator<MyObject>
{
private readonly IOtherService service;
public MyValidator(ISomeOtherService service)
{
// Here I want to be able to perform complex validation rules that may involve other services??
}
}
像这样的东西。我也愿意使用另一个验证库/方案吗?
谢谢!!