TenantIds class
Namespace: Tenantry · Package: Tenantry.Core · API reference
An extension point: for code that extends the package, such as another package that builds on it. An application rarely needs it.
Tenant ids as text, and the ids Tenantry reserves for "no tenant". Tenantry formats and parses tenant ids this way wherever they leave or enter the process: in log scopes and traces, in the headers Tenantry.Http and Tenantry.Pro's jobs and messages carry, and in the identifiers ITenantStore<TKey>.FindByIdentifierAsync reads by default.
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static class TenantIdsMethods
Format<TKey>(TKey)
Formats a tenant id with the invariant culture, so it reads the same on every machine: 42, a GUID's D format, or a string as it is.
public static string Format<TKey>(TKey tenantId) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
tenantIdTKey: The tenant id.
Returns: string: The id as text.
Exceptions:
ArgumentNullException:tenantIdis null.
IsReserved<TKey>(TKey?)
Returns true when tenantId is null, the key type's default (Empty, 0) or an empty string. ITenantContext<TKey>.CurrentTenantId has that value when no tenant is current, so no tenant can have it, and an entity whose TenantId has it belongs to no tenant yet.
public static bool IsReserved<TKey>(TKey? tenantId) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
tenantIdTKey: The tenant id.
Returns: bool: Whether the id is one Tenantry reserves for "no tenant".
TryParse<TKey>(string?, out TKey)
Parses text as a tenant id with the invariant culture, as TenantIds.Format<TKey> writes it. Returns false for text that does not parse and for the ids Tenantry reserves for "no tenant" (TenantIds.IsReserved<TKey>), so a parsed id can name a tenant.
public static bool TryParse<TKey>(string? text, out TKey tenantId) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type.
Parameters:
textstring: The text, from a header, a route value or a claim.tenantIdTKey: The parsed id, when this returns true.
Returns: bool: Whether text is a tenant id.
TenantEntity<TKey> class
Optional base class for tenant-owned entities, implementing ITenantEntity<TKey>tenantry-itenantentity.md.
TenantInactiveException class
Thrown when work is to run for a tenant that an ITenantActivityValidator<TKey>tenantry-itenantactivityvalidator.md refuses, such as a suspended tenant, for example by ITenantScopeFactory<TKey>.RunInScopeAsynctenantry-itenantscopefactory.md.