I am working on a system that has been architected using the suggested model in Billy McCafferty's article on codeproject
http://www.codeproject.com/aspnet/NHibe ... ctices.asp
and am trying to integrate this with the use of the Microsoft Validation Application Block (VAB) found in the latest version of the Enterprise Library.
I had implemented this such that when my IInterceptor implementation called OnSave or OnFlushDirty, the associated entity was validated. At the end of all validation, if any object failed validation an exception was thrown with the collection of validation messages.
What I then found was that because I'm using the session-per-request model, Flush would usually be called in the EndRequest event on the HttpModule. As a result, the exception would be thrown, but thrown after all soap processing had taken place, and therefore outside of the boundary within which anything useful could be done with it. Instead of catching a relevant exception on the front end, an error relating to incorrect response type would be displayed.
The other option I looked into was to call validate on the entity in the call to SaveOrUpdate, but it is necessary to validate the entire entity hierarchy, not just the entity. Therefore using [ObjectValidator] would allow the validation to propagate to associated entities, but this does not respect lazy loading, and a mass of data would be loaded from the database to be validated.
I realise there are flaws in both of these approaches, but am trying to find an approach that will work.
I am trying to achieve a validation implementation where the validation can all be localized to the entity being validated, that is called automatically so that the developer doesn't have to call Validate() in his code, and that will allow for the collection and reporting of all validation errors (rather than one by one).
Has anyone successfully integrated the VAB with NHibernate and if so how?