views:

558

answers:

1

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)
    {
        //...
    }
}
+3  A: 

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.

mookid8000