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.