NHibernate and WCF
I have run into some conceptual issues with using NHibernate with WCF. At the most basic level, I sought to duplicate the Session-Pre-Request functionality that I currently use for the web. This relies on the BeginRequest EndRequest events to create and close NHibernate's session.
Appernatly there is nothing in WCF that is similar to this, at least not globally. It has been suggested that I can use IDispatchMessegeInsepctor* to open/close the NHibernate session. This is good enough for the common case, althought it is still more work than I would like (you need to add the behavior to each service, instead of doing it globally).
One interesting thing that occured to me is using WCF PerSession services with NHibernate. Since NHibernate is now much more aggresive about release database connections, it make much more sense to use WCF PerSession while utilizing the Session Per Conversation pattern for NHibernate. This, however, I am not sure how to handle transperantly to the service...
* By the way, is someone else is strunk by how similar WCF is to the way Castle Windsor works?
Comments
This might be a little off topic, but since you're using WCF and NHibernate, I though you might find interest in an article that I wrote with Greg Banister about our experience building an app using WCF and NHibernate:
http://lunaverse.wordpress.com/2007/05/09/remoting-using-wcf-and-nhibernate/
Comment preview