We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Adeel Abass • 3 years ago

Hi,
could you point me to source code for your article please

Jono • 2 years ago

That's great if you are standing up a single service per tenant, but doesn't really have any sort of scalability.

You need a way to retrieve the tenant from the current request. This implementation gets it from the Request headers, but it's certainly better to get it from the User Claims, or some other more obfuscated or secure source.


using Microsoft.AspNetCore.Http;
using System;

public class HttpContextTenantProvider : ITenantProvider
{
IHttpContextAccessor _httpContextAccessor;

public HttpContextTenantProvider(IHttpContextAccessor httpContextAccessor) => _httpContextAccessor = httpContextAccessor;

public Guid GetTenantId()
{
/* Checks to ensure header exists and is a Guid, and add some error handling... */
return new Guid(_httpContextAccessor.HttpContext.Request.Headers["TenantId"]);
}
}