Created
September 25, 2019 11:35
-
-
Save merken/69015ef7707782bffe7b9ca2986b9286 to your computer and use it in GitHub Desktop.
TenantInfoMiddleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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