Reputation: 371
Is it possible to define a validation method (for businbess rules validation) that will be used by NHibernate.Validator? I mean something that exists in EntLib:
[HasSelfValidation()]
public class SomeClass
{
//...
[SelfValidation()]
public virtual void DoValidate(ValidationResults results)
{
//...
}
}
Upvotes: 2
Views: 1225
Reputation: 430
Have a look at The RulesEngine Project. Your business object won't have to be decorated with any attributes or have to implement any interfaces...
Upvotes: 0
Reputation: 18628
Yes, it can be done - but you will be missing a way to communicate more information on which rules were violated in the case of validation errors.
NHibernate Validator, to my knowledge, only provides the ability to specify a text message, the name of the class, and - in the case of property level validation attributes - the name of the violated property.
If your attribute HasSelfValidationAttribute
implement IRuleArgs
pointing to an IValidator
(or IInitializableValidator
), it has no way to communicate back anything else but a simple string Message
and the name of the class, which would probably be too little information if your demand is to validate "real business rules".
NHibernate Validator is great for simple validation scoped to the properties of a class, but it comes short when you need to do more complex validation.
Upvotes: 3