First Commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using ADS.Helpers.MultiTenant.Abstractions;
|
||||
using ADS.Helpers.MultiTenant.Configuration;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace ADS.Helpers.MultiTenant.Resolvers;
|
||||
|
||||
public sealed class HeaderTenantResolver : ITenantResolver
|
||||
{
|
||||
private readonly TenantOptions _opt;
|
||||
|
||||
public HeaderTenantResolver(IOptions<TenantOptions> opt) => _opt = opt.Value;
|
||||
|
||||
public string? Resolve(HttpContext context)
|
||||
{
|
||||
|
||||
if (context.Request.Headers.TryGetValue(_opt.HeaderName, out var value))
|
||||
return value.ToString();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_opt.DefaultTenantId))
|
||||
return _opt.DefaultTenantId;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user