TenantryServiceCollectionExtensions class
Namespace: Microsoft.Extensions.DependencyInjection · Package: Tenantry.Core · API reference
Registers Tenantry.
public static class TenantryServiceCollectionExtensionsMethods
AddTenantry<TKey>(IServiceCollection, Action<ITenantBuilder<TKey>>?)
Registers Tenantry for tenant keys of type TKey, then calls configure to add its features: a tenant store, how requests are resolved to tenants, connection strings, EF Core isolation and so on.
public static IServiceCollection AddTenantry<TKey>(this IServiceCollection services, Action<ITenantBuilder<TKey>>? configure = null) where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters:
TKey: The tenant identifier type (e.g.Guid,int,string). Must implementIEquatable<T>andIParsable<TSelf>.
Parameters:
servicesIServiceCollection: The application's service collection.configureAction<ITenantBuilder<TKey>>: Adds Tenantry's features, or null to register only the core services.
Returns: IServiceCollection: The same services for chaining.
Exceptions:
InvalidOperationException: Tenantry is already registered with another tenant key type.
The core services are the ambient tenant (ITenantContext<TKey> and ITenantContextSetter<TKey>), ITenantScopeFactory<TKey>, ITenantLookup<TKey> and ITenantStoreCache<TKey>, all singletons. They serve web applications, workers and console tools alike; the ASP.NET Core features come from the Tenantry.AspNetCore package.
Calling it again adds to the same registration, so a library can call it to make sure Tenantry is registered. An application uses one tenant key type: calling it with another throws.
builder.Services.AddTenantry<Guid>(tenant => tenant
.ResolveFromHeader("X-Tenant-Id")
.UseStore<AppTenantStore>());TenantryEfCoreTenantBuilderExtensions class
Extension methods for configuring EF Core tenant isolation on ITenantBuilder<TKey>tenantry-itenantbuilder-1.md.
TenantryTenantBuilderExtensions class
Tenantry's core features on ITenantBuilder<TKey>tenantry-itenantbuilder-1.md: the tenant store, its cache and per-tenant connection strings.