Docs
Tenantry ProAPI reference

DatabaseProvisioningService<TKey> class

Namespace: Tenantry.Pro.EfCore.MySql.Strategies.DatabasePerTenant · Package: Tenantry.Pro.EfCore.MySql · API reference

Creates a dedicated MySQL or MariaDB database for a tenant when called explicitly.

MySQL treats schemas and databases as synonyms. Therefore, only the database-per-tenant strategy is supported for MySQL/MariaDB. Schema-per-tenant is not available.

Inject this service in the code path that creates new tenants and call DatabaseProvisioningServiceBase<TKey>.ProvisionAsync explicitly. After provisioning, the database exists but contains no tables — apply EF Core migrations separately via dbContext.Database.MigrateAsync() or the migration orchestration service.

public sealed class DatabaseProvisioningService<TKey> : DatabaseProvisioningServiceBase<TKey>, ITenantInfrastructureProvisioner<TKey> where TKey : IEquatable<TKey>, IParsable<TKey>

Type parameters

  • TKey: The tenant identifier type.

Inherits DatabaseProvisioningServiceBase<TKey>.

Implements ITenantInfrastructureProvisioner<TKey>.

Constructors

DatabaseProvisioningService(ITenantStoreAccessor<TKey>, ITenantConnectionStringResolver<TKey>, ILicenseGuard, ILogger<DatabaseProvisioningService<TKey>>)

Creates the provisioning service. Resolved automatically by the DI container when you call pro.AddDatabaseProvisioning(); you do not normally construct it yourself.

public DatabaseProvisioningService(ITenantStoreAccessor<TKey> storeAccessor, ITenantConnectionStringResolver<TKey> connectionStrings, ILicenseGuard licenseGuard, ILogger<DatabaseProvisioningService<TKey>> logger)

Parameters:

Methods

BuildAdminConnectionString(string)

Returns a connection string that targets a server/admin database (one that always exists), derived from the tenant connection string, so CREATE DATABASE can be issued.

protected override string BuildAdminConnectionString(string tenantConnectionString)

Parameters:

  • tenantConnectionString string: The tenant's connection string, naming a database that may not exist yet.

Returns: string

CreateDatabaseIfNotExistsAsync(string, string, CancellationToken)

Issues the provider-specific, idempotent CREATE DATABASE against adminConnectionString. Implementations are responsible for identifier escaping.

protected override Task CreateDatabaseIfNotExistsAsync(string adminConnectionString, string databaseName, CancellationToken cancellationToken)

Parameters:

Returns: Task

ExtractDatabaseName(string)

Extracts the tenant database name from the tenant connection string.

protected override string ExtractDatabaseName(string tenantConnectionString)

Parameters:

  • tenantConnectionString string: The tenant's connection string.

Returns: string

On this page