C# Class Spring.Data.NHibernate.Support.SessionScope

Implementation of SessionScope that associates a single session within the using scope.

It is recommended to be used in the following type of scenario: using (new SessionScope()) { ... do multiple operation, possibly in multiple transactions. } At the end of "using", the session is automatically closed. All transactions within the scope use the same session, if you are using Spring's HibernateTemplate or using Spring's implementation of NHibernate 1.2's ICurrentSessionContext interface.

It is assumed that the session factory object name is called "SessionFactory". In case that you named the object in different way you can specify your can specify it in the application settings using the key Spring.Data.NHibernate.Support.SessionScope.SessionFactoryObjectName. Values for EntityInterceptorObjectName and SingleSessionMode can be specified similarly.

Note: The session is managed on a per thread basis on the thread that opens the scope instance. This means that you must never pass a reference to a SessionScope instance over to another thread!

Inheritance: IDisposable
Mostrar archivo Open project: spring-projects/spring-net Class Usage Examples

Protected Properties

Property Type Description
log ILog

Public Methods

Method Description
Close ( ) : void

Close the current view's session and unregisters from spring's TransactionSynchronizationManager.

Dispose ( ) : void

Call Close(),

Open ( ) : void

Opens a new session or participates in an existing session and registers with spring's TransactionSynchronizationManager.

SessionScope ( ) : System

Initializes a new instance of the SessionScope class in single session mode, associating a session with the thread. The session is opened lazily on demand.

SessionScope ( ISessionFactory sessionFactory, IInterceptor entityInterceptor, bool singleSession, FlushMode defaultFlushMode, bool open ) : System

Initializes a new instance of the SessionScope class.

SessionScope ( ISessionFactory sessionFactory, bool open ) : System

Initializes a new instance of the SessionScope class.

SessionScope ( Spring.Data.NHibernate.Support.SessionScopeSettings settings, bool open ) : System

Initializes a new instance of the SessionScope class.

SessionScope ( bool open ) : System

Initializes a new instance of the SessionScope class.

SessionScope ( string sectionName, Type namespaceType, bool open ) : System

Initializes a new instance of the SessionScope class.

SessionScope ( string sectionName, bool open ) : System

Initializes a new instance of the SessionScope class.

Private Methods

Method Description
DoClose ( bool isLogDebugEnabled ) : void
DoOpenSession ( ) : ISession
SetOpen ( bool isOpen ) : void

Sets a flag, whether this scope is in "open" state on the current logical thread.

SetParticipating ( bool participating ) : void

Gets/Sets a flag, whether this scope manages it's own session for the current logical thread or not.

Method Details

Close() public method

Close the current view's session and unregisters from spring's TransactionSynchronizationManager.
public Close ( ) : void
return void

Dispose() public method

Call Close(),
public Dispose ( ) : void
return void

Open() public method

Opens a new session or participates in an existing session and registers with spring's TransactionSynchronizationManager.
public Open ( ) : void
return void

SessionScope() public method

Initializes a new instance of the SessionScope class in single session mode, associating a session with the thread. The session is opened lazily on demand.
public SessionScope ( ) : System
return System

SessionScope() public method

Initializes a new instance of the SessionScope class.
public SessionScope ( ISessionFactory sessionFactory, IInterceptor entityInterceptor, bool singleSession, FlushMode defaultFlushMode, bool open ) : System
sessionFactory ISessionFactory /// The instance to be used for obtaining instances. ///
entityInterceptor IInterceptor /// Specify the to be set on each session provided by this instance. ///
singleSession bool /// Set whether to use a single session for each request. See property for details. ///
defaultFlushMode FlushMode /// Specify the flushmode to be applied on each session provided by this instance. ///
open bool /// If set to true associate a session with the thread. If false, another /// collaborating class will associate the session with the thread, potentially by calling /// the Open method on this class. ///
return System

SessionScope() public method

Initializes a new instance of the SessionScope class.
public SessionScope ( ISessionFactory sessionFactory, bool open ) : System
sessionFactory ISessionFactory /// The instance to be used for obtaining instances. ///
open bool /// If set to true associate a session with the thread. If false, another /// collaborating class will associate the session with the thread, potentially by calling /// the Open method on this class. ///
return System

SessionScope() public method

Initializes a new instance of the SessionScope class.
public SessionScope ( Spring.Data.NHibernate.Support.SessionScopeSettings settings, bool open ) : System
settings Spring.Data.NHibernate.Support.SessionScopeSettings An instance holding the scope configuration
open bool /// If set to true associate a session with the thread. If false, another /// collaborating class will associate the session with the thread, potentially by calling /// the Open method on this class. ///
return System

SessionScope() public method

Initializes a new instance of the SessionScope class.
public SessionScope ( bool open ) : System
open bool /// If set to true associate a session with the thread. If false, another /// collaborating class will associate the session with the thread, potentially by calling /// the Open method on this class. ///
return System

SessionScope() public method

Initializes a new instance of the SessionScope class.
public SessionScope ( string sectionName, Type namespaceType, bool open ) : System
sectionName string /// The name of the configuration section to read configuration settings from. /// See for more info. ///
namespaceType System.Type The type, who's full name is used for prefixing appSetting keys
open bool /// If set to true associate a session with the thread. If false, another /// collaborating class will associate the session with the thread, potentially by calling /// the Open method on this class. ///
return System

SessionScope() public method

Initializes a new instance of the SessionScope class.
public SessionScope ( string sectionName, bool open ) : System
sectionName string /// The name of the configuration section to read configuration settings from. /// See for more info. ///
open bool /// If set to true associate a session with the thread. If false, another /// collaborating class will associate the session with the thread, potentially by calling /// the Open method on this class. ///
return System

Property Details

log protected_oe property

The logging instance.
protected ILog log
return ILog