Skip to content

Add new session context implementation for TransactionScope #1907

Open
@ah1508

Description

@ah1508

It should be possible to bind a session lifecycle to a System.Transactions.TransactionScope.

An implementation of NHibernate.Context.ICurrentSessionContext would work as follow (method GetCurrentSession).

If first call for the current transaction

  1. opens a session (sessionFactory.OpenSession())
  2. register a callback for the System.Transactions.Transaction.Current.TransactionCompleted event, which flush the session (if transaction status is Committed) and close it.
  3. add the session to a IDictionary<string, ISession> where the key is the transaction identifier (Transaction.Current.TransactionInformation.LocalIdentifier) + sessionfactory hashcode and the value is the session newly created.

If not first call for the current transaction : return the session found in the IDictionary<string, ISession>

I found information about ISession and transaction scope synchronization, but I never got the expected result. I finally wrote an implementation of ICurrentSessionContext which works as described above. Is there something wrong in the implementation described here above ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions