I hereby claim:
- I am im5tu on github.
- I am im5tu (https://keybase.io/im5tu) on keybase.
- I have a public key whose fingerprint is 4DB4 4182 E554 B981 1860 CACB 176E 56F2 602C 4866
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
public static class CorrelationContext | |
{ | |
public static Stack<Guid> GetCorrelationStack() {} | |
public static Guid? GetCorrelationId() {} | |
public static IDisposable CreateCorrelation(Guid? correlationId = null) {} | |
public static IDisposable CreateCorrelationIfNotExists(Guid? correlationId = null) {} | |
} |
public static class CorrelationContext | |
{ | |
public static Stack<Guid> GetCorrelationStack() {} | |
public static Guid? GetCorrelationId() {} | |
public static IDisposable CreateCorrelation(Guid? correlationId = null) {} | |
public static IDisposable CreateCorrelationIfNotExists(Guid? correlationId = null) {} | |
} |
private static readonly AsyncLocal<Stack<Guid>> _correlationStack = new AsyncLocal<Stack<Guid>>(); | |
public static Stack<Guid> GetCorrelationStack() => _correlationStack.Value ?? new Stack<Guid>(); |
public static Guid? GetCorrelationId() | |
{ | |
var stack = GetCorrelationStack(); | |
if(stack.Count > 0) | |
return stack.Peek(); | |
return null; // TODO :: decide what you are going to do | |
} |
public static IDisposable CreateCorrelation(Guid? correlationId = null) | |
{ | |
if (_correlationStack.Value == null) | |
_correlationStack.Value = new Stack<Guid>(); | |
_correlationStack.Value.Push(correlationId ?? Guid.NewGuid()); | |
return new DisposeCorrelation(_correlationStack); | |
} |
public static IDisposable CreateCorrelationIfNotExists(Guid? correlationId = null) | |
{ | |
if(GetCorrelationStack().Count > 0) | |
return new EmptyDisposable(); | |
return CreateCorrelation(correlationId); | |
} |
private class DisposeCorrelation : IDisposable | |
{ | |
private readonly AsyncLocal<Stack<Guid>> _localStack; | |
public DisposeCorrelation(AsyncLocal<Stack<Guid>> localStack) | |
{ | |
_localStack = localStack; | |
} | |
public void Dispose() | |
{ |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using(CorrelationContext.CreateCorrelationIfNotExists()) | |
{ | |
Console.WriteLine(CorrelationContext.GetCorrelationId()); | |
using(CorrelationContext.CreateCorrelationIfNotExists()) | |
{ |
name: 0.1.0 | |
trigger: | |
branches: | |
include: | |
- master | |
- hotfix/* | |
- release/* | |
- feature/* | |
- bugfix/* | |
- backlog/* |