using System.Collections.Concurrent; using System.Threading; namespace ASC.Common.Notify.Engine { /// /// Provides a way to set contextual data that flows with the call and /// async context of a test or invocation. /// public static class CallContext { static ConcurrentDictionary> state = new ConcurrentDictionary>(); /// /// Stores a given object and associates it with the specified name. /// /// The name with which to associate the new item in the call context. /// The object to store in the call context. public static void SetData(string name, object data) => state.GetOrAdd(name, _ => new AsyncLocal()).Value = data; /// /// Retrieves an object with the specified name from the . /// /// The name of the item in the call context. /// The object in the call context associated with the specified name, or if not found. public static object GetData(string name) => state.TryGetValue(name, out var data) ? data.Value : null; } }