Docs
Tenantry CoreAPI reference

ITenantConnectionStringResolver<TKey> interface

Namespace: Tenantry.Core · Package: Tenantry.Core · API reference

Returns tenants' connection strings, as configured by TenantConnectionStringOptions<TKey>.

Registered as a singleton by UseConnectionStrings. The parameterless overloads use the current tenant (from the request, or from a scope opened with ITenantScopeFactory<TKey>); the others take the tenant explicitly, for code such as migration runners that visits tenants without making each one current.

With a regular AddDbContext, resolve in the options callback, which runs for every new context: options.UseSqlServer(sp.GetRequiredService<ITenantConnectionStringResolver<Guid>>().Resolve()). Do not do this with AddDbContextPool or AddPooledDbContextFactory: their options callback runs once, so every pooled context would keep the first tenant's connection string.

public interface ITenantConnectionStringResolver<TKey> where TKey : IEquatable<TKey>, IParsable<TKey>

Type parameters

Derived types: TenantConnectionStringResolver<TKey>.

Methods

Resolve()

Returns the current tenant's connection string.

string Resolve()

Returns: string

Exceptions:

Resolve(ITenantDescriptor<TKey>)

Returns tenant's connection string.

string Resolve(ITenantDescriptor<TKey> tenant)

Parameters:

Returns: string

Exceptions:

ResolveAsync(CancellationToken)

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

ValueTask<string> ResolveAsync(CancellationToken cancellationToken = default)

Parameters:

  • cancellationToken CancellationToken: Cancels the lookup.

Returns: ValueTask<string>

Exceptions:

ResolveAsync(ITenantDescriptor<TKey>, CancellationToken)

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

ValueTask<string> ResolveAsync(ITenantDescriptor<TKey> tenant, CancellationToken cancellationToken = default)

Parameters:

  • tenant ITenantDescriptor<TKey>: The tenant whose connection string to return.
  • cancellationToken CancellationToken: Cancels the lookup.

Returns: ValueTask<string>

Exceptions:

  • InvalidOperationException: The delegate returned an empty value.

On this page