using System.Data.Common; using Volo.Abp; using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.SqlSugarCore; /// /// SqlSugar数据库上下文创建上下文 /// public class SqlSugarDbContextCreationContext { private static readonly AsyncLocal CurrentContextHolder = new AsyncLocal(); /// /// 获取当前上下文 /// public static SqlSugarDbContextCreationContext Current => CurrentContextHolder.Value!; /// /// 连接字符串名称 /// public string ConnectionStringName { get; } /// /// 连接字符串 /// public string ConnectionString { get; } /// /// 现有数据库连接 /// public DbConnection? ExistingConnection { get; internal set; } /// /// 构造函数 /// public SqlSugarDbContextCreationContext( string connectionStringName, string connectionString) { ConnectionStringName = connectionStringName; ConnectionString = connectionString; } /// /// 使用指定的上下文 /// public static IDisposable Use(SqlSugarDbContextCreationContext context) { var previousContext = Current; CurrentContextHolder.Value = context; return new DisposeAction(() => CurrentContextHolder.Value = previousContext); } }