Docs
Tenantry CoreAPI reference

API reference

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

Tenantry.AspNetCore

TypeKindSummary
IAspNetCoreTenantBuilder<TKey>interfaceFluent builder for configuring multi-tenancy services. Obtained from ServiceCollectionExtensions.AddTenantry<TKey>.

Tenantry.AspNetCore.Attributes

TypeKindSummary
AllowMissingTenantAttributeclassAllows an endpoint or controller action to execute without a resolved tenant.
RequireTenantAttributeclassRequires Tenantry to resolve a tenant before the endpoint or controller action executes.

Tenantry.AspNetCore.Extensions

TypeKindSummary
ApplicationBuilderExtensionsclassExtension methods for adding Tenantry middleware to the request pipeline.
EndpointConventionBuilderExtensionsclassExtension methods for applying Tenantry endpoint metadata.
ServiceCollectionExtensionsclassExtension methods for registering Tenantry services.

Tenantry.AspNetCore.Resolution

TypeKindSummary
ClaimTenantResolverclassResolves the tenant from a claim on the current request principal.
HeaderTenantResolverclassResolves the tenant from a request header (e.g. X-Tenant-Id).
ITenantResolverinterfaceExtracts a tenant identifier from an HTTP request.
QueryStringTenantResolverclassResolves the tenant from a query string parameter (e.g. ?tenantId=acme).
RouteValueTenantResolverclassResolves the tenant from a route value (e.g. /api/{tenant}/resource).
SubdomainTenantResolverclassResolves the tenant from the first subdomain segment of the request host. For example, acme.app.example.com resolves to acme.

Tenantry.Core

Tenantry.Core

TypeKindSummary
ITenantBuilder<TKey>interfaceMinimal builder interface that captures TKey and exposes the service collection. Satellite packages (e.g. Tenantry.EfCore) add extension methods on this interface so users only specify TKey once in AddTenantry.
ITenantConnectionStringResolver<TKey>interfaceReturns tenants' connection strings, as configured by TenantConnectionStringOptions<TKey>.
ITenantContext<TKey>interfaceProvides read-only access to the currently resolved tenant for the active request scope. Registered as a singleton backed by AsyncLocal<T> — the value is per-async-context (effectively per HTTP request) rather than per-instance.
ITenantDescriptor<TKey>interfaceRepresents a resolved tenant.
ITenantScope<TKey>interfaceRepresents a scoped interface for managing tenant-specific context within the application.
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.
ITenantScoped<TKey>interfaceMarker interface for objects that belong to a specific tenant.
ITenantServiceScope<TKey>interfaceA dependency-injection scope with a tenant active, created by ITenantScopeFactory<TKey>.
ITenantStore<TKey>interfacePersists and retrieves tenant definitions.
ITenantStoreAccessor<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.
MissingTenantBehaviorenumPolicy for what happens when a tenant-scoped operation runs without a resolved tenant context.
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 ITenantConnectionStringResolver<TKey>.
TenantConnectionStringResolver<TKey>classThe default ITenantConnectionStringResolver<TKey>: calls the configured delegates on every resolution, without caching.
TenantDescriptor<TKey>classDefault implementation of ITenantDescriptor<TKey>.
TenantScoped<TKey>classOptional base class for tenant-owned objects. Implements ITenantScoped<TKey> for convenience.

Tenantry.Core.Exceptions

TypeKindSummary
TenantIsolationViolationExceptionclassThrown when a cross-tenant data isolation violation is detected during a SaveChanges or SaveChangesAsync call, or when a bulk update would set TenantId.
TenantNotResolvedExceptionclassThrown when a tenant could not be resolved from the current request context and the operation requires a resolved tenant.

Tenantry.Core.Extensions

TypeKindSummary
ConnectionStringExtensionsclassRegisters per-tenant connection strings: TenantConnectionStringOptions<TKey> and ITenantConnectionStringResolver<TKey>.
ServiceCollectionExtensionsclassExtension methods for registering core Tenantry services.

Tenantry.Core.Stores

TypeKindSummary
InMemoryTenantStore<TKey>classAn ITenantStore<TKey> backed by an in-memory dictionary.

Tenantry.EfCore

Tenantry.EfCore

TypeKindSummary
EfCoreIsolationOptionsclassOptions for configuring EF Core tenant isolation registration. Passed to builder.AddEfCoreIsolation(options => ...).
ITenantAwareDbContext<TKey>interfaceMarks a DbContext as tenant-aware, exposing the current tenant identifier for use in EF Core global query filters.
MultiTenantDbContext<TKey>classOptional base DbContext that automatically applies tenant query filters in OnModelCreating.

Tenantry.EfCore.Extensions

TypeKindSummary
DbContextOptionsBuilderExtensionsclassExtension methods for wiring Tenantry into DbContextOptionsBuilder.
TenantBuilderEfCoreExtensionsclassExtension methods for configuring EF Core tenant isolation on ITenantBuilder<TKey>.
TenantDbContextPoolExtensionsclassDbContext pooling for applications that give each tenant its own database.
TenantModelBuilderExtensionsclassExtension methods for ModelBuilder that apply tenant isolation to all entities implementing ITenantScoped<TKey>.

On this page