Table of Contents

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

options SchemaIsolationOptions

The configuration options for schema isolation.

logger ILogger<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

tenant TenantInfo

The tenant information.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<Result>

A task representing the asynchronous operation.

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

tenant TenantInfo

The tenant information.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<Result<string>>

A task representing the asynchronous operation with the connection string.

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

tenant TenantInfo

The tenant information.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<Result<string>>

A task representing the asynchronous operation with the schema name.