The object-relational mapper for .NET

uNHaddins Persistence Conversation – Part 1: Configuration

This post was previously published in my blog here

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)

A working example can be found in the examples folder of uNHAddins trunk, here.

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 

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.

Finally you set the way you are going to create sessions in your application (sessionFactory provider is the id to an implementation of ISessionFactoryProvider)

<component id="uNhAddIns.sessionFactory"
      type="NHibernate.ISessionFactory, NHibernate"

This is all the magic we need to set it up all. The following post will be about using it in our application.

If you want to see it working follow the link to the source at the beginning of the post.

Posted Fri, 06 February 2009 06:33:00 AM by Gustavo
Filed under: NHibernate, Session

comments powered by Disqus
© NHibernate Community 2024