I am added a value to the InvocationContext
dictionary, however it doesn't persist to the next call. i.e. each call in the chain that's intercepted is returning false for InvocationContext.ContainsKey("tracing-id")
.
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
Guid tracingId;
if (!input.InvocationContext.ContainsKey(TRACING_ID))
{
tracingId = _tracingIdProvider.NewTracingId();
input.InvocationContext.Add(TRACING_ID, tracingId);
}
else
{
tracingId = (Guid)input.InvocationContext[TRACING_ID];
}
var methodReturn = getNext()(input, getNext);
return methodReturn;
}
I can add an entry to the InvocationContext
, however, when getNext()(input, getNext)
is invoked and the next call is intercepted the InvocationContext
is empty.
Am I misunderstanding how InvocationContext
is used? If so, what's the correct way to persist something like an ID from one method call to the next?