Is this a good way to wire up NHibernate using StructureMap?
I am blogging this code snippet in order to ask some people at altnetseattle if this is a good implementation or not.
I want to know whether or not this is considered a good way of wiring up NHibernate using StructureMap. I am making use of the registry DSL feature, this code would get called somewhere in my bootstrapper.
Elsewhere in my code, my Repositories simply have a constructor dependency on ISession.
NHibernateConfiguration is my class that does all configuration of NHibernate using FluentNHibernate.
1: public class DataAccessRegistry : Registry
2: {
3: public DataAccessRegistry()
4: {
5: // NHibernate ISessionFactory
6: ForRequestedType<ISessionFactory>()
7: .CacheBy(InstanceScope.Singleton)
8: .TheDefault.Is.ConstructedBy(() => new NHibernateConfiguration().BuildSessionFactory());
9:
10: // NHibernate ISession
11: ForRequestedType<ISession>()
12: .CacheBy(InstanceScope.Hybrid)
13: .TheDefault.Is.ConstructedBy(() => ObjectFactory.GetInstance<ISessionFactory>().OpenSession());
14: }
15: }

