Class SchemaIsolationStrategy
- Namespace
- Compendium.Multitenancy
- Assembly
- Compendium.Multitenancy.dll
Implements tenant isolation by providing each tenant with a separate schema within a shared database. This strategy balances isolation with resource efficiency.
public sealed class SchemaIsolationStrategy : ITenantIsolationStrategy
- Inheritance
-
SchemaIsolationStrategy
- Implements
- Inherited Members
Constructors
SchemaIsolationStrategy(SchemaIsolationOptions, ILogger<SchemaIsolationStrategy>)
Initializes a new instance of the SchemaIsolationStrategy class.
public SchemaIsolationStrategy(SchemaIsolationOptions options, ILogger<SchemaIsolationStrategy> logger)
Parameters
optionsSchemaIsolationOptionsThe configuration options for schema isolation.
loggerILogger<SchemaIsolationStrategy>The logger for this strategy.
Exceptions
- ArgumentNullException
Thrown when options or logger is null.
Methods
EnsureTenantResourcesAsync(TenantInfo, CancellationToken)
Ensures that the necessary schema resources exist for a tenant. Creates the tenant schema, tables, and sets up initial data.
public Task<Result> EnsureTenantResourcesAsync(TenantInfo tenant, CancellationToken cancellationToken = default)
Parameters
tenantTenantInfoThe tenant information.
cancellationTokenCancellationTokenThe cancellation token.
Returns
GetConnectionStringAsync(TenantInfo, CancellationToken)
Gets the database connection string for a specific tenant. All tenants share the same database connection in schema isolation.
public Task<Result<string>> GetConnectionStringAsync(TenantInfo tenant, CancellationToken cancellationToken = default)
Parameters
tenantTenantInfoThe tenant information.
cancellationTokenCancellationTokenThe cancellation token.
Returns
GetSchemaNameAsync(TenantInfo, CancellationToken)
Gets the schema name for a specific tenant. Builds the schema name from the template using the tenant ID.
public Task<Result<string>> GetSchemaNameAsync(TenantInfo tenant, CancellationToken cancellationToken = default)
Parameters
tenantTenantInfoThe tenant information.
cancellationTokenCancellationTokenThe cancellation token.