Where and how is NH session closed in Orchard?

Topics: Core, General
Dec 24, 2013 at 7:55 AM
Edited Dec 25, 2013 at 2:36 AM
In Nicholas Blumhardt's article,he explain all components will automatically be disposed when the corresponding lifetimeScope invoke Dispose() method.
However, I noticed the NH Session instance in class "SessionLocator" is created by SessionFactory, instead of being resolved by Ioc. And in SessionLocator's Dispose() method, the code is all about transaction, nothing to do with session.

Apparently every NH session is closed at the end of request, because Orchard works well. but how does it complete that?
I can't find any _session.Close() or _session.Dispose() in source code.
Dec 25, 2013 at 2:45 AM
Or is session bound to the current thread after SessionFactory.OpenSession() invoked?
Dec 25, 2013 at 5:45 AM
Oh, I've found the answer. After the NHibernate 1.0.x , there is a new ConnectionReleaseMode called "AfterTransaction".
In this mode, committing a transaction will close the connection.