using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.SqlSugarCore { /// /// 异步本地数据库上下文访问器 /// 用于在异步流中保存和访问数据库上下文 /// public sealed class AsyncLocalDbContextAccessor { private readonly AsyncLocal _currentScope; /// /// 获取单例实例 /// public static AsyncLocalDbContextAccessor Instance { get; } = new(); /// /// 获取或设置当前数据库上下文 /// public ISqlSugarDbContext? Current { get => _currentScope.Value; set => _currentScope.Value = value; } /// /// 初始化异步本地数据库上下文访问器 /// private AsyncLocalDbContextAccessor() { _currentScope = new AsyncLocal(); } } }