hello-shop/samples/MultiTenancySample/MultiTenancySample.ServiceDefaults/CurrentTenant.cs

32 lines
789 B
C#
Raw Normal View History

2024-07-05 11:25:58 +00:00
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
namespace MultiTenancySample.ServiceDefaults
2024-04-28 08:00:15 +00:00
{
public class CurrentTenant : ICurrentTenant
{
public string? TenantId { get; private set; }
public IDisposable SetTenant(string? tenantId)
{
string? parentTenantId = TenantId;
TenantId = tenantId;
return new DisposeAction(() =>
{
TenantId = parentTenantId;
});
}
public class DisposeAction(Action action) : IDisposable
{
void IDisposable.Dispose()
{
action();
GC.SuppressFinalize(this);
}
}
}
}