Skip to content

Instantly share code, notes, and snippets.

@JamesLouie
Created December 2, 2018 01:30
public class TenantInterceptor
{
private const string TenantHeader = "x-tenant-id";
private readonly RequestDelegate _next;
public TenantInterceptor(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
if (httpContext.Request.Headers.TryGetValue(TenantHeader, out var tenantHeaders))
{
var tenantId = tenantHeaders.First();
httpContext.Items[TenantHeader] = tenantId;
}
await _next(httpContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment