refactor: ai+人工重构优化 framework

This commit is contained in:
橙子
2025-02-23 03:06:06 +08:00
parent f9341fd2ac
commit 3e07ca822a
61 changed files with 2604 additions and 1260 deletions

View File

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