zeroframework/Services/Identity/ZeroFramework.IdentityServer.API/Tenants/TenantMiddleware.cs

21 lines
717 B
C#
Raw Permalink Normal View History

2023-12-05 09:22:48 +00:00
using ZeroFramework.IdentityServer.API.IdentityStores;
namespace ZeroFramework.IdentityServer.API.Tenants
{
public class TenantMiddleware(ICurrentTenant currentTenant, ITenantProvider tenantProvider) : IMiddleware
{
private readonly ICurrentTenant _currentTenant = currentTenant;
private readonly ITenantProvider _tenantProvider = tenantProvider;
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
IdentityTenant? currentTenant = await _tenantProvider.GetTenantAsync();
using (_currentTenant.Change(currentTenant?.Id, currentTenant?.Name))
{
await next(context);
}
}
}
}