using NPin.Framework.SqlSugarCore.Abstractions;

namespace NPin.Framework.SqlSugarCore;

public class AsyncLocalDbContextAccessor
{
    public static AsyncLocalDbContextAccessor Instance { get; } = new();

    private readonly AsyncLocal<ISqlSugarDbContext> _currentScope;

    public ISqlSugarDbContext? Current
    {
        get => _currentScope.Value;
        set => _currentScope.Value = value;
    }

    public AsyncLocalDbContextAccessor()
    {
        _currentScope = new();
    }
}