CurrentTenantConnectionString<TKey> class
Namespace: Tenantry · Package: Tenantry.Core · API reference
Returns the current tenant's connection string, through the registered ITenantConnectionStringProvider<TKey>.
Registered as a singleton by UseConnectionStrings, for code that opens its own connections. For EF Core, Tenantry.EfCore's AddDbContextPerTenantDatabase connects each context to its tenant's database, pooled or not.
Do not read it in the options callback of AddDbContextPool or AddPooledDbContextFactory: that callback runs once, so every pooled context would keep the first tenant's connection string.
public sealed class CurrentTenantConnectionString<TKey> where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters
TKey: The tenant identifier type. SeeITenantDescriptor<TKey>for constraints.
Constructors
CurrentTenantConnectionString(ITenantContext<TKey>, ITenantConnectionStringProvider<TKey>)
Returns the current tenant's connection string, through the registered ITenantConnectionStringProvider<TKey>.
public CurrentTenantConnectionString(ITenantContext<TKey> tenantContext, ITenantConnectionStringProvider<TKey> connectionStrings)Parameters:
tenantContextITenantContext<TKey>: Supplies the current tenant.connectionStringsITenantConnectionStringProvider<TKey>: Returns a tenant's connection string.
Registered as a singleton by UseConnectionStrings, for code that opens its own connections. For EF Core, Tenantry.EfCore's AddDbContextPerTenantDatabase connects each context to its tenant's database, pooled or not.
Do not read it in the options callback of AddDbContextPool or AddPooledDbContextFactory: that callback runs once, so every pooled context would keep the first tenant's connection string.
Methods
Get()
Returns the current tenant's connection string.
public string Get()Returns: string
Exceptions:
TenantNotResolvedException: No tenant is current.InvalidOperationException: OnlyTenantConnectionStringOptions<TKey>.GetConnectionStringAsyncis configured (useCurrentTenantConnectionString<TKey>.GetAsync), or the delegate returned an empty value.
GetAsync(CancellationToken)
Returns the current tenant's connection string, using the asynchronous delegate if configured.
public ValueTask<string> GetAsync(CancellationToken cancellationToken = default)Parameters:
cancellationTokenCancellationToken: Cancels the lookup.
Returns: ValueTask<string>
Exceptions:
TenantNotResolvedException: No tenant is current.InvalidOperationException: The delegate returned an empty value.