@ -1,10 +1,10 @@
using Microsoft.Extensions.Options ;
using Volo.Abp.MultiTenancy ;
using Volo.DependencyInjection ;
using Volo.ExtensionMethods.Collections.Generic ;
namespace Volo.Abp.Data.MultiTenancy
{
//TODO: It would be better to use composition over inheritance on connection string resolve progress!
//TODO: Create a replace service registration convention, instead of custom registration in AbpMultiTenancyModule?
[DisableConventionalRegistration]
@ -26,20 +26,40 @@ namespace Volo.Abp.Data.MultiTenancy
public override string Resolve ( string connectionStringName = null )
{
var tenant = _multiTenancyManager . CurrentTenant ;
//No current tenant, fallback to default logic
if ( tenant = = null )
{
return base . Resolve ( connectionStringName ) ;
}
var connectionString = _tenantConnectionStringStore . GetConnectionStringOrNull ( tenant . Id , connectionStringName ) ;
if ( connectionString = = null )
//Requesting default connection string
if ( connectionString Name = = null )
{
return base . Resolve ( connectionStringName ) ;
return _tenantConnectionStringStore . GetDefaultConnectionStringOrNull ( tenant . Id ) ? ?
Options . ConnectionStrings . Default ;
}
//TODO: If given tenant did not specified a connectionStringName specific connection string, then use the default connection string for connectionStringName, not tenant's default database
//Requesting specific connection string
var connString = _tenantConnectionStringStore . GetConnectionStringOrNull ( tenant . Id , connectionStringName ) ;
if ( connString ! = null )
{
return connString ;
}
/ * Requested a specific connection string , but it ' s not specified for the tenant .
* - If it ' s specified in options , use it .
* - If not , use tenant ' s default conn string .
* /
var connStringInOptions = Options . ConnectionStrings . GetOrDefault ( connectionStringName ) ;
if ( connStringInOptions ! = null )
{
return connStringInOptions ;
}
return connectionString ;
return _tenantConnectionStringStore . GetDefaultConnectionStringOrNull ( tenant . Id ) ? ?
Options . ConnectionStrings . Default ;
}
}
}