TenantConnectionStringResolver<TKey> class
Namespace: Tenantry.Core · Package: Tenantry.Core · API reference
The default ITenantConnectionStringResolver<TKey>: calls the configured delegates on every resolution, without caching.
Public so that other resolvers (for example a caching one) can wrap it. UseConnectionStrings registers it as a singleton, and forwards ITenantConnectionStringResolver<TKey> to it.
public sealed class TenantConnectionStringResolver<TKey> : ITenantConnectionStringResolver<TKey> where TKey : IEquatable<TKey>, IParsable<TKey>Type parameters
TKey: The tenant identifier type. SeeITenantDescriptor<TKey>for constraints.
Implements ITenantConnectionStringResolver<TKey>.
Constructors
TenantConnectionStringResolver(ITenantContext<TKey>, TenantConnectionStringOptions<TKey>)
The default ITenantConnectionStringResolver<TKey>: calls the configured delegates on every resolution, without caching.
public TenantConnectionStringResolver(ITenantContext<TKey> tenantContext, TenantConnectionStringOptions<TKey> options)Parameters:
tenantContextITenantContext<TKey>: Supplies the current tenant.optionsTenantConnectionStringOptions<TKey>: The delegates that return a tenant's connection string.
Public so that other resolvers (for example a caching one) can wrap it. UseConnectionStrings registers it as a singleton, and forwards ITenantConnectionStringResolver<TKey> to it.
Methods
Resolve()
Returns the current tenant's connection string.
public string Resolve()Returns: string
Exceptions:
TenantNotResolvedException: No tenant is current.InvalidOperationException: OnlyTenantConnectionStringOptions<TKey>.GetConnectionStringAsyncis configured (useITenantConnectionStringResolver<TKey>.ResolveAsync), or the delegate returned an empty value.
Resolve(ITenantDescriptor<TKey>)
Returns tenant's connection string.
public string Resolve(ITenantDescriptor<TKey> tenant)Parameters:
tenantITenantDescriptor<TKey>: The tenant whose connection string to return.
Returns: string
Exceptions:
InvalidOperationException: OnlyTenantConnectionStringOptions<TKey>.GetConnectionStringAsyncis configured (useITenantConnectionStringResolver<TKey>.ResolveAsync), or the delegate returned an empty value.
ResolveAsync(CancellationToken)
Returns the current tenant's connection string, using the asynchronous delegate if configured.
public ValueTask<string> ResolveAsync(CancellationToken cancellationToken = default)Parameters:
cancellationTokenCancellationToken: Cancels the lookup.
Returns: ValueTask<string>
Exceptions:
TenantNotResolvedException: No tenant is current.InvalidOperationException: The delegate returned an empty value.
ResolveAsync(ITenantDescriptor<TKey>, CancellationToken)
Returns tenant's connection string, using the asynchronous delegate if configured.
public ValueTask<string> ResolveAsync(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.