Table of Contents

Class DatabaseIsolationStrategy

Namespace
Compendium.Multitenancy
Assembly
Compendium.Multitenancy.dll

Implements tenant isolation by providing each tenant with a separate database. This strategy offers the highest level of isolation but requires more database resources.

public sealed class DatabaseIsolationStrategy : ITenantIsolationStrategy
Inheritance
DatabaseIsolationStrategy
Implements
Inherited Members

Constructors

DatabaseIsolationStrategy(DatabaseIsolationOptions, ILogger<DatabaseIsolationStrategy>)

Initializes a new instance of the DatabaseIsolationStrategy class.

public DatabaseIsolationStrategy(DatabaseIsolationOptions options, ILogger<DatabaseIsolationStrategy> logger)

Parameters

options DatabaseIsolationOptions

The configuration options for database isolation.

logger ILogger<DatabaseIsolationStrategy>

The logger for this strategy.

Exceptions

ArgumentNullException

Thrown when options or logger is null.

Methods

EnsureTenantResourcesAsync(TenantInfo, CancellationToken)

Ensures that the necessary database resources exist for a tenant. Creates the tenant database, runs migrations, 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. Uses tenant-specific connection string if available, otherwise builds from template.

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. In database isolation, returns the default schema since each tenant has its own database.

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.