NHibernate rarities: SessionFactoryObjectFactory

time to read 1 min | 121 words

I had a discussion about session factory management in NHibernate just now, and I was asked why NHibernate isn’t managing that internally.

Well… it does, actually. As you can guess, SessionFactoryObjectFactory is the one responsible for that, and you can use GetNamedInstance() to get a specific session factory.

It isn’t used much (as a matter of fact, I have never seen it used), I am not quite sure why. I think that it is easier to just manage it ourselves. There are very rare cases where you would need more than one or two session factories, and when you run into them, you usually want to do other things as well, such as lazy session factory initialization and de-initialization.