Sunday, May 10, 2009

NHibernate Validator

In a domain driven design codebase, all value types should be immutable. Also, where concerns such as concurrency raises its head, defining as many entities as possible as immutable can really simplify things.

NHibernate validator helps you to ensure that value/entity types never enter an invalid state.

You can implement validation using NHibernate Validator by declarative tags, fluent interfaces or defining the validation in an xml file. I really like the latter mechanism i.e. defining validation in an xml file as you are not polluting entity/value type ddfinition with validation logic.

In relation to ORMs, one major problem that has been discussed numerous times in DDD forums is that when a value type is retrieved from the database, it may be in an invalid state. Before with NHibernate, we got around this by validating the object retrieved manually via a PostLoadEventListener handler. However NHibernate Validator has full integration with the NHibernate lifecycle and it really makes it easy now to validate post load.

Overall, Im very impressed with NHibernate Validator...

No comments:

Post a Comment