31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
namespace Fitness_core_BE.Infra.Tenancy
|
|
{
|
|
// Request-scoped tenant info, populated once per request by TenantResolutionAttribute
|
|
// (Helpers/TenantResolutionAttribute.cs) so downstream repos/services can read the
|
|
// caller's resolved TenantId instead of re-deriving ClientId ad hoc via UserRoleHelper.
|
|
public interface ITenantContext
|
|
{
|
|
// Client owner / Staff: their one gym. Customer: the gym validated from X-Tenant-Id
|
|
// for this request, if any was sent. Admin: always null (see IsPlatformAdmin).
|
|
Guid? TenantId { get; }
|
|
bool IsPlatformAdmin { get; }
|
|
bool IsResolved { get; }
|
|
|
|
void SetTenant(Guid? tenantId, bool isPlatformAdmin);
|
|
}
|
|
|
|
public class TenantContext : ITenantContext
|
|
{
|
|
public Guid? TenantId { get; private set; }
|
|
public bool IsPlatformAdmin { get; private set; }
|
|
public bool IsResolved { get; private set; }
|
|
|
|
public void SetTenant(Guid? tenantId, bool isPlatformAdmin)
|
|
{
|
|
TenantId = tenantId;
|
|
IsPlatformAdmin = isPlatformAdmin;
|
|
IsResolved = true;
|
|
}
|
|
}
|
|
}
|