Created
March 7, 2012 20:18
-
-
Save dvilchez/1995747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DispatchOperationRuntime | |
| { | |
| //... | |
| void UninitializeCallContextCore(ref MessageRpc rpc) | |
| { | |
| IClientChannel channel = rpc.Channel.Proxy as IClientChannel; | |
| int offset = this.Parent.CallContextCorrelationOffset; | |
| try | |
| { | |
| for (int i = this.CallContextInitializers.Length - 1; i >= 0; i--) | |
| { | |
| ICallContextInitializer initializer = this.CallContextInitializers[i]; | |
| initializer.AfterInvoke(rpc.Correlation[offset + i]); | |
| } | |
| } | |
| catch (Exception e) | |
| { | |
| // thread-local storage may be corrupt | |
| DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "ICallContextInitializer.BeforeInvoke threw an exception of type {0}: {1}", e.GetType(), e.Message)); | |
| } | |
| } | |
| //.... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NhSessionPerCallContext:ICallContextInitializer | |
| { | |
| //... | |
| public void AfterInvoke(object correlationState) | |
| { | |
| var session = CurrentSessionContext.Unbind(_sessionFactory); | |
| if (session != null) | |
| { | |
| try | |
| { | |
| session.Flush(); | |
| if (session.Transaction.IsActive) | |
| { | |
| session.Transaction.Commit(); | |
| } | |
| } | |
| catch (Exception e) | |
| { | |
| if (session.Transaction.IsActive) | |
| { | |
| session.Transaction.Rollback(); | |
| } | |
| throw; | |
| } | |
| finally | |
| { | |
| session.Close(); | |
| session.Dispose(); | |
| } | |
| } | |
| } | |
| //... | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment