Docs
Tenantry CoreAPI reference

API reference

View as Markdown

Every public type in the packages, generated from their XML documentation comments. The guides explain how the pieces fit together; this reference is for the details of each type and member.

Tenantry.AspNetCore

Microsoft.AspNetCore.Builder

TypeKindSummary
TenantryApplicationBuilderExtensionsclassAdds Tenantry's tenant resolution to the request pipeline.
TenantryEndpointConventionBuilderExtensionsclassExtension methods for applying Tenantry endpoint metadata.

Microsoft.Extensions.DependencyInjection

TypeKindSummary
TenantryAspNetCoreTenantBuilderExtensionsclassTenantry's ASP.NET Core features on ITenantBuilder<TKey>: how a request is resolved to a tenant, whether endpoints need one, and who may use it. app.UseTenantry() applies them to requests.

Tenantry.AspNetCore

TypeKindSummary
AllowMissingTenantAttributeclassAllows an endpoint or controller action to execute without a resolved tenant.
ClaimTenantResolverclassResolves the tenant from a claim on the current request principal.
HeaderTenantResolverclassResolves the tenant from a request header (e.g. X-Tenant-Id).
HostTenantResolverclassResolves the tenant from the request's host name, for tenants that bring their own domain: a request to app.acme.com has the identifier app.acme.com, which your tenant store's ITenantStore<TKey>.FindByIdentifierAsync maps to a tenant.
HostTenantResolverOptionsclassOptions for HostTenantResolver, set with tenant.ResolveFromHost(o => …).
ITenantAccessValidator<TKey>interfaceDecides whether a request may use the tenant it names.
ITenantResolverinterfaceReads a tenant identifier from an HTTP request: the tenant's id, or a name the tenant store maps to a tenant, such as a subdomain or a host name (see ITenantStore<TKey>.FindByIdentifierAsync).
QueryStringTenantResolverclassResolves the tenant from a query string parameter (e.g. ?tenantId=acme).
RequireTenantAttributeclassRequires Tenantry to resolve a tenant before the endpoint or controller action executes.
RouteValueTenantResolverclassResolves the tenant from a route value (e.g. /api/{tenant}/resource).
SubdomainTenantResolverclassResolves the tenant from the subdomain of the request host. For example, acme.app.example.com resolves to acme.
SubdomainTenantResolverOptionsclassOptions for SubdomainTenantResolver, set with tenant.ResolveFromSubdomain(o => …).
TenantRejectedContext<TKey>classA request that app.UseTenantry() rejects, passed to TenantResolutionOptions<TKey>.OnRejected.
TenantRejectionReasonenumWhy app.UseTenantry() rejects a request to an endpoint that needs a tenant.
TenantResolutionOptions<TKey>classHow app.UseTenantry() treats requests: whether they need a tenant, the status code of each rejection, and the events it raises. Configure it with tenant.ConfigureResolution(o => …) or tenant.RequireTenantByDefault().
TenantResolvedContext<TKey>classThe request whose tenant app.UseTenantry() made current, passed to TenantResolutionOptions<TKey>.OnResolved.
TenantryAspNetCoreTelemetryclassThe names app.UseTenantry() records requests under, for OpenTelemetry's AddSource and AddMeter, and for log filters. The request's tenant itself goes under TenantTelemetry's names.

Tenantry.Caching

Microsoft.Extensions.DependencyInjection

TypeKindSummary
TenantryCachingTenantBuilderExtensionsclassKeeps cached data per tenant.

Tenantry.Caching

TypeKindSummary
ITenantDistributedCacheinterfaceThe registered IDistributedCache, with every key under the current tenant's prefix, for code that uses IDistributedCache directly and keeps data per tenant. Without a tenant, every call throws TenantNotResolvedException.
SharedHybridCacheclassThe HybridCache for entries every tenant shares (exchange rates, reference data), where IsolateCaches() makes the injected HybridCache keep entries per tenant.

Tenantry.Core

Microsoft.Extensions.DependencyInjection

TypeKindSummary
TenantryServiceCollectionExtensionsclassRegisters Tenantry.
TenantryTenantBuilderExtensionsclassTenantry's core features on ITenantBuilder<TKey>: the tenant store, its cache, invalidation across instances, and per-tenant connection strings.

Tenantry

TypeKindSummary
CurrentTenantConnectionString<TKey>classReturns the current tenant's connection string, through the registered ITenantConnectionStringProvider<TKey>.
ITenantActivity<TKey>interfaceWhether a tenant may have work run for it, as the registered ITenantActivityValidator<TKey>s decide.
ITenantActivityValidator<TKey>interfaceDecides whether a tenant may have work run for it: requests, background work, jobs and messages.
ITenantBuilderinterfaceThe builder AddTenantry passes to its configuration callback, without the tenant key type. Features that take a type parameter of their own register through ITenantBuilder.Add, so their callers never repeat the key type.
ITenantBuilder<TKey>interfaceThe builder AddTenantry<TKey> passes to its configuration callback.
ITenantConnectionStringProvider<TKey>interfaceReturns a tenant's connection string, as configured by TenantConnectionStringOptions<TKey>.
ITenantContext<TKey>interfaceThe current tenant, for a request or an ITenantScopeFactory<TKey> scope.
ITenantContextSetter<TKey>interfaceMakes a tenant current for the calling code, for code that has already found the tenant and needs no new dependency-injection scope. Most code uses ITenantScopeFactory<TKey> instead, which also creates a scope for the tenant's services.
ITenantDescriptorinterfaceA tenant, without its identifier type: the base of ITenantDescriptor<TKey>, for code that does not need the tenant's id, such as TenantDescriptorExtensions.As<TTenant>.
ITenantDescriptor<TKey>interfaceRepresents a resolved tenant.
ITenantEntity<TKey>interfaceMarks an entity that belongs to a tenant.
ITenantInvalidationHandler<TKey>interfaceClears data kept per tenant when the tenant changes, or, registered with BroadcastInvalidations, publishes the invalidation to the application's other instances. Every registered handler runs on ITenantInvalidator<TKey> invalidation, with or without CacheTenants.
ITenantInvalidator<TKey>interfaceClears everything Tenantry keeps for a tenant when the tenant changes: its cached copy (with CacheTenants) and what each ITenantInvalidationHandler<TKey> keeps, such as Tenantry.Caching's entries, cached responses and Tenantry.Options' values.
ITenantLookup<TKey>interfaceReads tenants from the registered ITenantStore<TKey> on behalf of singletons, such as hosted services, resolving the store from a fresh dependency-injection scope for each call.
ITenantScope<TKey>interfaceA dependency-injection scope with a tenant current, created by ITenantScopeFactory<TKey>.
ITenantScopeFactory<TKey>interfaceOpens tenant scopes for work that runs outside an HTTP request: hosted services, queue consumers, scheduled jobs and console tools. Each scope pairs a fresh dependency-injection scope with an active tenant, so scoped services such as a DbContext are created for that tenant and isolated to it.
ITenantStore<TKey>interfaceFinds and lists the application's tenants.
InMemoryTenantStore<TKey>classAn ITenantStore<TKey> backed by an in-memory dictionary.
TenantConnectionStringOptions<TKey>classHow to find each tenant's connection string, for applications that give tenants their own database (or route them to different servers). Configure it with UseConnectionStrings and read connection strings through ITenantConnectionStringProvider<TKey>, or the current tenant's through CurrentTenantConnectionString<TKey>.
TenantDescriptor<TKey>classDefault implementation of ITenantDescriptor<TKey>.
TenantDescriptorExtensionsclassReads a tenant as the application's own tenant type.
TenantEntity<TKey>classOptional base class for tenant-owned entities, implementing ITenantEntity<TKey>.
TenantInactiveExceptionclassThrown when work is to run for a tenant that an ITenantActivityValidator<TKey> refuses, such as a suspended tenant, for example by ITenantScopeFactory<TKey>.RunInScopeAsync.
TenantNotFoundExceptionclassThrown when a tenant is looked up by its id and the tenant store has no tenant with that id, for example by ITenantScopeFactory<TKey>.RunInScopeAsync.
TenantNotResolvedExceptionclassThrown when an operation needs a current tenant and none is current. Derived types cover a named tenant that does not exist (TenantNotFoundException) or is inactive (TenantInactiveException).
TenantPropagationclassHow Tenantry carries a tenant from one process to another: Tenantry.Http's outgoing requests, Tenantry.AspNetCore's ResolveFromPropagationHeader(...) on the receiving side, and Tenantry.Pro's Hangfire, MassTransit, Quartz.NET and Rebus integrations.
TenantStoreCacheOptionsclassHow Tenantry caches the tenants it reads from the tenant store. Set with tenant.CacheTenants(o => …).
TenantTelemetryclassThe names Tenantry records a tenant under in traces and logs: Tenantry.AspNetCore's app.UseTenantry() for a request, and Tenantry.Pro for jobs, messages and background work.

Extension points

For code that extends the package, such as another package that builds on it. An application rarely needs them.

TypeNamespaceKindSummary
ITenantKeyTypeTenantryinterfaceThe tenant key type the application registered Tenantry with, for code that has only a service provider, such as a health check registration or a host extension, so its callers never repeat the key type.
ITenantKeyTypeVisitor<TResult>TenantryinterfaceCode that needs the tenant key type, given it by ITenantKeyType.
ITenantRegistrationTenantryinterfaceA registration that needs the tenant key type, added through ITenantBuilder.Add. Packages use it for builder methods that take a type parameter of their own, such as a DbContext type.
TenantIdsTenantryclassTenant 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.

Tenantry.EfCore

Microsoft.EntityFrameworkCore

TypeKindSummary
TenantryDbContextOptionsBuilderExtensionsclassExtension methods for wiring Tenantry into DbContextOptionsBuilder.
TenantryEntityTypeBuilderExtensionsclassMarks entity types in the model for Tenantry.

Microsoft.Extensions.DependencyInjection

TypeKindSummary
TenantryEfCoreTenantBuilderExtensionsclassExtension methods for configuring EF Core tenant isolation on ITenantBuilder<TKey>.

Tenantry.EfCore

TypeKindSummary
EfCoreIsolationOptionsclassOptions for EF Core tenant isolation: the application's, set with tenant.ConfigureEfCoreIsolation(options => …), or one context's, set with options.UseTenantry(o => …).
MissingTenantBehaviorenumWhat SaveChanges does when it writes tenant-owned entities and no tenant is current. Set with EfCoreIsolationOptions.OnMissingTenant.
SaveWithoutTransactionBehaviorenumWhat SaveChanges does when Database.AutoTransactionBehavior is Never, no transaction is open, and some rows it writes are tenant-checked by another of its statements. Set with EfCoreIsolationOptions.OnSaveWithoutTransaction.
SharedAcrossTenantsAttributeclassMarks an entity type whose rows every tenant shares, such as a country list or the tenant table itself.
TenantIsolationViolationExceptionclassThrown when EF Core would read or write across tenants. TenantIsolationViolationException.Kind says which check failed.
TenantIsolationViolationKindenumWhich isolation check threw a TenantIsolationViolationException.
TenantryQueryFiltersclassThe names of the query filters Tenantry adds or names on EF Core 10 and later.
UnmarkedEntityTypeBehaviorenumWhat a context does when its model has tenant-owned entity types and also entity types that are neither tenant-owned nor marked as shared across tenants. Set with EfCoreIsolationOptions.OnUnmarkedEntityType.

Extension points

For code that extends the package, such as another package that builds on it. An application rarely needs them.

TypeNamespaceKindSummary
ITenantDbContextOptionsContributorTenantry.EfCoreinterfaceAdds to the options of every DbContext that uses UseTenantry().
ITenantModelContributorTenantry.EfCoreinterfaceAdds to the model of every DbContext that uses UseTenantry().
TenantContextGuardTenantry.EfCoreclassAn interceptor that checks a context before it opens a connection, before every command it runs and before SaveChanges, so a context that would reach the wrong tenant's data throws instead.
TenantModelTenantry.EfCoreclassReads which entity types of an EF Core model Tenantry isolates, for packages and tests that build on it.

Tenantry.Http

Microsoft.Extensions.DependencyInjection

TypeKindSummary
TenantryHttpClientBuilderExtensionsclassSends the current tenant with an HTTP or gRPC client's requests.
TenantryHttpTenantBuilderExtensionsclassSends the current tenant to the services an application calls over HTTP or gRPC.

Tenantry.Options

Microsoft.Extensions.DependencyInjection

TypeKindSummary
TenantryOptionsTenantBuilderExtensionsclassOptions with values per tenant.

Tenantry.Options

TypeKindSummary
TenantOptionsBuilder<TKey>classSets options per tenant, in tenant.ConfigurePerTenant(...): each Configure or ConfigureAll names an options type and what differs for each tenant.

On this page