Skip to content

Commit 7fbe02f

Browse files
committed
One more time
1 parent 88f8443 commit 7fbe02f

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ public void EnlistInDistributedTransactionIfNeeded(ISessionImplementor session)
3232
if (transaction == null)
3333
return;
3434

35-
session.TransactionContext = new DistributedTransactionContext();
35+
var notification = new PrepareTransactionNotification(session, transaction);
3636

3737
transaction.EnlistVolatile(
38-
new PrepareTransactionNotification(session, transaction),
38+
notification,
3939
EnlistmentOptions.EnlistDuringPrepareRequired);
4040

41+
session.TransactionContext = notification;
42+
4143
transaction.EnlistVolatile(
4244
new TransactionCompletionNotification(session),
4345
EnlistmentOptions.None);
@@ -62,16 +64,7 @@ public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork wo
6264
}
6365
}
6466

65-
class DistributedTransactionContext : ITransactionContext
66-
{
67-
public bool ShouldCloseSessionOnDistributedTransactionCompleted { get; set; }
68-
69-
public void Dispose()
70-
{
71-
}
72-
}
73-
74-
class PrepareTransactionNotification : IEnlistmentNotification
67+
class PrepareTransactionNotification : IEnlistmentNotification, ITransactionContext
7568
{
7669
System.Transactions.Transaction _transaction;
7770

@@ -83,11 +76,12 @@ public PrepareTransactionNotification(ISessionImplementor session, System.Transa
8376
_transaction = transaction.Clone();
8477
}
8578

79+
public bool ShouldCloseSessionOnDistributedTransactionCompleted { get; set; }
80+
8681
void IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
8782
{
8883
using (new SessionIdLoggingContext(_session.SessionId))
8984
{
90-
9185
try
9286
{
9387
using (var tx = new TransactionScope(_transaction))
@@ -143,6 +137,16 @@ void IEnlistmentNotification.InDoubt(Enlistment enlistment)
143137
{
144138
enlistment.Done();
145139
}
140+
141+
public void Dispose()
142+
{
143+
if (!ReferenceEquals(_transaction, null))
144+
_transaction.Dispose();
145+
_transaction = null;
146+
if (!ReferenceEquals(_session, null))
147+
_session.TransactionContext = null;
148+
_session = null;
149+
}
146150
}
147151

148152
class TransactionCompletionNotification : IEnlistmentNotification

0 commit comments

Comments
 (0)