Last active
October 6, 2015 21:28
-
-
Save i3arnon/fd0ed2d637c57c289511 to your computer and use it in GitHub Desktop.
Fixed LogicalFlow using an ImmutableStack
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 static class LogicalFlow | |
{ | |
private static ImmutableStack<Guid> LogicalStack | |
{ | |
get | |
{ | |
return CallContext.LogicalGetData("LogicalFlow") as ImmutableStack<Guid> ?? ImmutableStack.Create<Guid>(); | |
} | |
set | |
{ | |
CallContext.LogicalSetData("LogicalFlow", value); | |
} | |
} | |
public static Guid CurrentId | |
{ | |
get | |
{ | |
var logicalStack = LogicalStack; | |
return logicalStack.IsEmpty ? Guid.Empty : logicalStack.Peek(); | |
} | |
} | |
public static IDisposable StartScope() | |
{ | |
LogicalStack = LogicalStack.Push(Guid.NewGuid()); // Here's where the CallContext is copied using copy-on-write | |
return new Stopper(); | |
} | |
private static void StopScope() | |
{ | |
LogicalStack = LogicalStack.Pop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment