IAspNetCoreTenantBuilder<TKey> interface
Namespace: Tenantry.AspNetCore · Package: Tenantry.AspNetCore · API reference
Fluent builder for configuring multi-tenancy services. Obtained from ServiceCollectionExtensions.AddTenantry<TKey>.
public interface IAspNetCoreTenantBuilder<TKey> : ITenantBuilder<TKey> where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters
TKey: The tenant identifier type. Must implementIEquatable<T>andIParsable<TSelf>.
Methods
RequireTenantByDefault()
Requires tenant resolution by default for requests that pass through Tenantry middleware.
IAspNetCoreTenantBuilder<TKey> RequireTenantByDefault()Returns: IAspNetCoreTenantBuilder<TKey>
ResolveFromClaim(string)
Resolves the tenant from a claim on the current request principal.
IAspNetCoreTenantBuilder<TKey> ResolveFromClaim(string claimType = "tenant_id")Parameters:
claimTypestring: The type of the claim that carries the tenant identifier.
Returns: IAspNetCoreTenantBuilder<TKey>
ResolveFromHeader(string)
Resolves the tenant from the specified HTTP request header.
IAspNetCoreTenantBuilder<TKey> ResolveFromHeader(string headerName)Parameters:
headerNamestring: The name of the header that carries the tenant identifier, such asX-Tenant-Id.
Returns: IAspNetCoreTenantBuilder<TKey>
ResolveFromQueryString(string)
Resolves the tenant from a query string parameter.
IAspNetCoreTenantBuilder<TKey> ResolveFromQueryString(string parameterName = "tenantId")Parameters:
parameterNamestring: The name of the query string parameter that carries the tenant identifier.
Returns: IAspNetCoreTenantBuilder<TKey>
For local development and testing only — do not use in production. Query string parameters are routinely logged by servers, proxies, and analytics, and are trivially spoofable, so they are not a safe tenant-resolution mechanism for production traffic.
ResolveFromRouteValue(string)
Resolves the tenant from a route value.
IAspNetCoreTenantBuilder<TKey> ResolveFromRouteValue(string routeValueKey = "tenant")Parameters:
routeValueKeystring: The name of the route value that carries the tenant identifier, as in/api/{tenant}/orders.
Returns: IAspNetCoreTenantBuilder<TKey>
ResolveFromSubdomain()
Resolves the tenant from the first subdomain of the request host.
IAspNetCoreTenantBuilder<TKey> ResolveFromSubdomain()Returns: IAspNetCoreTenantBuilder<TKey>
UseResolver(Func<IServiceProvider, ITenantResolver>)
Registers a custom ITenantResolver implementation with a factory method.
IAspNetCoreTenantBuilder<TKey> UseResolver(Func<IServiceProvider, ITenantResolver> factory)Parameters:
factoryFunc<IServiceProvider, ITenantResolver>: Creates the resolver from the application's services.
Returns: IAspNetCoreTenantBuilder<TKey>
UseResolver(ITenantResolver)
Registers a custom ITenantResolver implementation with a concrete instance.
IAspNetCoreTenantBuilder<TKey> UseResolver(ITenantResolver resolver)Parameters:
resolverITenantResolver: The resolver to use for every request.
Returns: IAspNetCoreTenantBuilder<TKey>
UseResolver<TResolver>()
Registers a custom ITenantResolver implementation.
IAspNetCoreTenantBuilder<TKey> UseResolver<TResolver>() where TResolver : class, ITenantResolverType parameters:
TResolver: The resolver type, created through dependency injection.
Returns: IAspNetCoreTenantBuilder<TKey>
ValidateTenantAccess(Func<HttpContext, ITenantDescriptor<TKey>, bool>)
Adds a synchronous tenant access validator.
IAspNetCoreTenantBuilder<TKey> ValidateTenantAccess(Func<HttpContext, ITenantDescriptor<TKey>, bool> validator)Parameters:
validatorFunc<HttpContext, ITenantDescriptor<TKey>, bool>: Returns true when the request may use the resolved tenant; otherwise the request is refused with403 Forbidden.
Returns: IAspNetCoreTenantBuilder<TKey>
ValidateTenantAccess(Func<HttpContext, ITenantDescriptor<TKey>, CancellationToken, ValueTask<bool>>)
Adds an asynchronous tenant access validator.
IAspNetCoreTenantBuilder<TKey> ValidateTenantAccess(Func<HttpContext, ITenantDescriptor<TKey>, CancellationToken, ValueTask<bool>> validator)Parameters:
validatorFunc<HttpContext, ITenantDescriptor<TKey>, CancellationToken, ValueTask<bool>>: Returns true when the request may use the resolved tenant; otherwise the request is refused with403 Forbidden. It receives the request's cancellation token.
Returns: IAspNetCoreTenantBuilder<TKey>
ValidateTenantAccessByClaim(string)
Validates tenant access by matching the resolved tenant against claims on the current request principal.
IAspNetCoreTenantBuilder<TKey> ValidateTenantAccessByClaim(string claimType)Parameters:
claimTypestring: The type of the claims that list the tenant identifiers the principal may use. A request for any other tenant is refused.
Returns: IAspNetCoreTenantBuilder<TKey>