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??
}
}
このようなもの。また、別の検証ライブラリ/スキームを使用することもできますか?
ありがとう!!