uNHAddins Conversation and motivations where widely presented on Fabio’s blog here.
The focus of this series of posts is configuring the Persistence Conversation aspect using uNHAddins and CastleAdapter targeting a Windows Forms Application (some of the concepts are easily movable to a Web application, but there are much more frameworks and examples matching this)
The following assumptions are made about your repositories/Dao’s for this to work.
1) You are injecting the ISessionFactory in the repositories and not an ISession.
2) You are using GetCurrentSession() instead of OpenSession() to get the active session inside the repositories / dao’s.
3) You are able to use Castle for Dependency Injection, i hope more adapters will come in the future, but this is one that it is implemented and it is enough popular.
First thing we should do is to decide the conversation context strategy and set it in the hibernate cfg. For this example it is:
<property name="current_session_context_class">uNhAddIns.SessionEasier.Conversations.ThreadLocalConversationalSessionContext, uNhAddIns</property>
Next thing is configuring castle to accept the PersistenceConversationalFacility, which will bring AOP in a similar manner to the TransactionalFacility from castle, and all the factories and services that compose a conversation.
The configuration for the facilities and default uNHAddins components for Castle can be found here . There are some cases when you will want to play with the factories, this will be the reason for another post.
This is all the magic we need to set it up all. The following post will be about using it in our application.<component id="uNhAddIns.sessionFactory"type="NHibernate.ISessionFactory, NHibernate"factoryId="sessionFactoryProvider"factoryCreate="GetFactory"><parameters><factoryId>uNhAddIns</factoryId></parameters></component>
If you want to see it working follow the link to the source at the beginning of the post.