using System.Collections.Concurrent; using System.Threading; using Abp.Dependency; namespace Abp.Runtime.Remoting { public class AsyncLocalAmbientDataContext : IAmbientDataContext, ISingletonDependency { private static readonly ConcurrentDictionary> AsyncLocalDictionary = new ConcurrentDictionary>(); public void SetData(string key, object value) { var asyncLocal = AsyncLocalDictionary.GetOrAdd(key, (k) => new AsyncLocal()); asyncLocal.Value = value; } public object GetData(string key) { var asyncLocal = AsyncLocalDictionary.GetOrAdd(key, (k) => new AsyncLocal()); return asyncLocal.Value; } } }