Skip to content

Instantly share code, notes, and snippets.

@merken
Created September 25, 2019 11:35
Show Gist options
  • Save merken/69015ef7707782bffe7b9ca2986b9286 to your computer and use it in GitHub Desktop.
Save merken/69015ef7707782bffe7b9ca2986b9286 to your computer and use it in GitHub Desktop.
TenantInfoMiddleware
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace efcore_tenancy.Infrastructure
{
public class TenantInfoMiddleware
{
private readonly RequestDelegate _next;
public TenantInfoMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
var tenantInfo = context.RequestServices.GetRequiredService<TenantInfo>();
var tenantName = context.Request.Headers["Tenant"];
if (string.IsNullOrEmpty(tenantName))
tenantName = "dell";
tenantInfo.Name = tenantName;
// Call the next delegate/middleware in the pipeline
await _next(context);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment