Browse Source

Merge pull request #21046 from abpframework/MultiTenantConnectionStringResolver

Use the logic in the `ResolveAsync` method to implement the `Resolve` method.
pull/21055/head
Halil İbrahim Kalkan 2 years ago
committed by GitHub
parent
commit
5eeaf3908f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs

28
framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs

@ -118,27 +118,25 @@ public class MultiTenantConnectionStringResolver : DefaultConnectionStringResolv
return connString!;
}
//Fallback to tenant's default connection string if available
if (!tenantDefaultConnectionString.IsNullOrWhiteSpace())
{
return tenantDefaultConnectionString!;
}
//Try to find the specific connection string for given name
var connStringInOptions = Options.ConnectionStrings.GetOrDefault(connectionStringName);
if (!connStringInOptions.IsNullOrWhiteSpace())
//Fallback to the mapped database for the specific connection string
var database = Options.Databases.GetMappedDatabaseOrNull(connectionStringName);
if (database != null && database.IsUsedByTenants)
{
return connStringInOptions!;
connString = tenant.ConnectionStrings?.GetOrDefault(database.DatabaseName);
if (!connString.IsNullOrWhiteSpace())
{
//Found for the tenant
return connString!;
}
}
//Fallback to the global default connection string
var defaultConnectionString = Options.ConnectionStrings.Default;
if (!defaultConnectionString.IsNullOrWhiteSpace())
//Fallback to tenant's default connection string if available
if (!tenantDefaultConnectionString.IsNullOrWhiteSpace())
{
return defaultConnectionString!;
return tenantDefaultConnectionString!;
}
throw new AbpException("No connection string defined!");
return base.Resolve(connectionStringName);
}
protected virtual async Task<TenantConfiguration?> FindTenantConfigurationAsync(Guid tenantId)

Loading…
Cancel
Save