public interface ITenantService
{
    string GetCurrentTenant();
}

public sealed class TenantService : ITenantService
{
    private readonly HttpContext _httpContext;
    private readonly ITenantIdentificationService _tenantService;

    public TenantService(IHttpContextAccessor accessor, ITenantIdentificationService tenantService)
    {
        _httpContext = accessor.HttpContext;
        _tenantService = tenantService;
    }

    public string GetCurrentTenant() => _tenantService.GetCurrentTenant(_httpContext);    
}

Tenant Identification Strategies

  1. Host Header: the tenant will be inferred by the host header sent by browser when accessing the application.
  2. Query String: a query string parameter will be used to distinguish between the different tenants.
  3. Source IP: you may want that requests originating from the same IPs get the same tenant all the time.

Database Access Strategies

When it comes to retrieving different values from a relational database, we have essentially three options:

Other Requirements