HttpTenantContext
AgentPrism.AspNetCore.dllResolves the tenant from the current HTTP request.
public sealed class HttpTenantContext : ITenantContextInheritance
Section titled “Inheritance”Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”The class is a singleton and works through IHttpContextAccessor. A scoped implementation would produce a captive dependency in singleton services that inject ITenantContext (stores, decorators), and ASP.NET Core would report this as a startup error.
Resolution order:
- If multi-tenancy is disabled → the default tenant.
- If a claim type is set and the user passed authentication → the claim.
- If header resolution is enabled → the header.
- If none apply → the default tenant.
While the claim is set, the header is never read. Otherwise an authenticated user could access another tenant’s data simply by adding a header.
Constructors
Section titled “Constructors”HttpTenantContext(IHttpContextAccessor, IOptions<AgentPrismOptions>, IOptions<AgentPrismTenancyOptions>)
Section titled “ HttpTenantContext(IHttpContextAccessor, IOptions<AgentPrismOptions>, IOptions<AgentPrismTenancyOptions>)”Creates a new HTTP tenant context.
public HttpTenantContext(IHttpContextAccessor accessor, IOptions<AgentPrismOptions> coreOptions, IOptions<AgentPrismTenancyOptions> tenancyOptions)Parameters
Section titled “Parameters”accessor IHttpContextAccessor
The accessor that resolves the current request.
coreOptions IOptions<AgentPrismOptions>
The AgentPrism settings.
tenancyOptions IOptions<AgentPrismTenancyOptions>
The tenant resolution settings.
Exceptions
Section titled “Exceptions”A dependency is null.
Properties
Section titled “Properties”TenantId
Section titled “ TenantId”The current tenant’s identifier. Never returns empty.
public string TenantId { get; }Property Value
Section titled “Property Value”Remarks
Section titled “Remarks”If AmbientTenantScope.Current is set (a scheduled job is running and there is no HTTP context), that value is preferred over HTTP resolution.
On a request authenticated with an API key, the tenant is resolved from
the KEY’s tenant_id — this comes BEFORE the claim or the header.
The key PROVES a secret; the header is only the client’s
DECLARATION. AgentPrism.AgentPrismEndpointFilter already rejects the
request with 403 if the header conflicts with the key’s tenant, so by the
time a request reaches this point, the two either match or the header is
absent.
Methods
Section titled “Methods”IsValidTenantId(string?)
Section titled “ IsValidTenantId(string?)”Says whether a tenant id is well-formed.
public static bool IsValidTenantId(string? tenantId)Parameters
Section titled “Parameters”tenantId string?
The value to check.
Returns
Section titled “Returns”true if the value is acceptable.
Remarks
Section titled “Remarks”The id is a text column in the database and travels as a query parameter; SQL injection is not possible. A format constraint still applies: an unchecked value would be reflected as-is into logs, the audit trail, and the UI.