TenantConnectionStringProvider<TKey> class
Namespace: Tenantry · Package: Tenantry.Core · API reference
The default ITenantConnectionStringProvider<TKey>: calls the configured delegates on every call, without caching.
Public so that other providers (for example a caching one) can wrap it. UseConnectionStrings registers it as a singleton, and forwards ITenantConnectionStringProvider<TKey> to it.
public sealed class TenantConnectionStringProvider<TKey> : ITenantConnectionStringProvider<TKey> where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters
TKey: The tenant identifier type. SeeITenantDescriptor<TKey>for constraints.
Implements ITenantConnectionStringProvider<TKey>.
Constructors
TenantConnectionStringProvider(TenantConnectionStringOptions<TKey>)
The default ITenantConnectionStringProvider<TKey>: calls the configured delegates on every call, without caching.
public TenantConnectionStringProvider(TenantConnectionStringOptions<TKey> options)Parameters:
optionsTenantConnectionStringOptions<TKey>: The delegates that return a tenant's connection string.
Public so that other providers (for example a caching one) can wrap it. UseConnectionStrings registers it as a singleton, and forwards ITenantConnectionStringProvider<TKey> to it.
Methods
Get(ITenantDescriptor<TKey>)
Returns tenant's connection string.
public string Get(ITenantDescriptor<TKey> tenant)Parameters:
tenantITenantDescriptor<TKey>: The tenant whose connection string to return.
Returns: string
Exceptions:
InvalidOperationException: OnlyTenantConnectionStringOptions<TKey>.GetConnectionStringAsyncis configured (useITenantConnectionStringProvider<TKey>.GetAsync), or the delegate returned an empty value.
GetAsync(ITenantDescriptor<TKey>, CancellationToken)
Returns tenant's connection string, using the asynchronous delegate if configured.
public ValueTask<string> GetAsync(ITenantDescriptor<TKey> tenant, CancellationToken cancellationToken = default)Parameters:
tenantITenantDescriptor<TKey>: The tenant whose connection string to return.cancellationTokenCancellationToken: Cancels the lookup.
Returns: ValueTask<string>
Exceptions:
InvalidOperationException: The delegate returned an empty value.