Deal.Api/Http -> Services/Models/Extensions; Contracts/Integrations и SharedKernel/Tenants -> Abstractions/Models; extension-классы telegram/ml -> Extensions. namespace/using/FQN мигрированы, using дедуплицированы.
25 lines
729 B
C#
25 lines
729 B
C#
using Deal.SharedKernel.Tenants.Abstractions;
|
|
using Deal.SharedKernel.Tenants.Models;
|
|
|
|
namespace Deal.Infrastructure.Data;
|
|
|
|
/// <summary>
|
|
/// Контекст тенанта на AsyncLocal: пробрасывается через весь запрос.
|
|
/// </summary>
|
|
public sealed class TenantContext : ITenantContext
|
|
{
|
|
private static readonly AsyncLocal<TenantId?> Current = new();
|
|
|
|
public TenantId? TenantId => Current.Value;
|
|
|
|
public bool HasTenant => Current.Value is not null;
|
|
|
|
public string? SchemaName => Current.Value?.SchemaName;
|
|
|
|
/// <inheritdoc />
|
|
public void SetTenant(TenantId tenantId) => Current.Value = tenantId;
|
|
|
|
/// <inheritdoc />
|
|
public void Reset() => Current.Value = null;
|
|
}
|