@@ -32,12 +32,14 @@ public void EnlistInDistributedTransactionIfNeeded(ISessionImplementor session)
32
32
if ( transaction == null )
33
33
return ;
34
34
35
- session . TransactionContext = new DistributedTransactionContext ( ) ;
35
+ var notification = new PrepareTransactionNotification ( session , transaction ) ;
36
36
37
37
transaction . EnlistVolatile (
38
- new PrepareTransactionNotification ( session , transaction ) ,
38
+ notification ,
39
39
EnlistmentOptions . EnlistDuringPrepareRequired ) ;
40
40
41
+ session . TransactionContext = notification ;
42
+
41
43
transaction . EnlistVolatile (
42
44
new TransactionCompletionNotification ( session ) ,
43
45
EnlistmentOptions . None ) ;
@@ -62,16 +64,7 @@ public void ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork wo
62
64
}
63
65
}
64
66
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
75
68
{
76
69
System . Transactions . Transaction _transaction ;
77
70
@@ -83,11 +76,12 @@ public PrepareTransactionNotification(ISessionImplementor session, System.Transa
83
76
_transaction = transaction . Clone ( ) ;
84
77
}
85
78
79
+ public bool ShouldCloseSessionOnDistributedTransactionCompleted { get ; set ; }
80
+
86
81
void IEnlistmentNotification . Prepare ( PreparingEnlistment preparingEnlistment )
87
82
{
88
83
using ( new SessionIdLoggingContext ( _session . SessionId ) )
89
84
{
90
-
91
85
try
92
86
{
93
87
using ( var tx = new TransactionScope ( _transaction ) )
@@ -143,6 +137,16 @@ void IEnlistmentNotification.InDoubt(Enlistment enlistment)
143
137
{
144
138
enlistment . Done ( ) ;
145
139
}
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
+ }
146
150
}
147
151
148
152
class TransactionCompletionNotification : IEnlistmentNotification
0 commit comments