Docs
Tenantry CoreAPI reference

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

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:

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:

GetAsync(CancellationToken)

Returns the current tenant's connection string, using the asynchronous delegate if configured.

public ValueTask<string> GetAsync(CancellationToken cancellationToken = default)

Parameters:

  • cancellationToken CancellationToken: Cancels the lookup.

Returns: ValueTask<string>

Exceptions:

On this page