mirror of https://github.com/abpframework/abp.git
committed by
GitHub
3 changed files with 77 additions and 42 deletions
@ -0,0 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.MultiTenancy |
|||
{ |
|||
public interface ITenantConfigurationProvider |
|||
{ |
|||
Task<TenantConfiguration> GetAsync(bool saveResolveResult = false); |
|||
} |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.MultiTenancy |
|||
{ |
|||
public class TenantConfigurationProvider : ITenantConfigurationProvider, ITransientDependency |
|||
{ |
|||
protected virtual ITenantResolver TenantResolver { get; } |
|||
protected virtual ITenantStore TenantStore { get; } |
|||
protected virtual ITenantResolveResultAccessor TenantResolveResultAccessor { get; } |
|||
|
|||
public TenantConfigurationProvider( |
|||
ITenantResolver tenantResolver, |
|||
ITenantStore tenantStore, |
|||
ITenantResolveResultAccessor tenantResolveResultAccessor) |
|||
{ |
|||
TenantResolver = tenantResolver; |
|||
TenantStore = tenantStore; |
|||
TenantResolveResultAccessor = tenantResolveResultAccessor; |
|||
} |
|||
|
|||
public virtual async Task<TenantConfiguration> GetAsync(bool saveResolveResult = false) |
|||
{ |
|||
var resolveResult = TenantResolver.ResolveTenantIdOrName(); |
|||
|
|||
if (saveResolveResult) |
|||
{ |
|||
TenantResolveResultAccessor.Result = resolveResult; |
|||
} |
|||
|
|||
TenantConfiguration tenant = null; |
|||
if (resolveResult.TenantIdOrName != null) |
|||
{ |
|||
tenant = await FindTenantAsync(resolveResult.TenantIdOrName); |
|||
|
|||
if (tenant == null) |
|||
{ |
|||
throw new BusinessException( |
|||
code: "Volo.AbpIo.MultiTenancy:010001", |
|||
message: "Tenant not found!", |
|||
details: "There is no tenant with the tenant id or name: " + resolveResult.TenantIdOrName |
|||
); |
|||
} |
|||
} |
|||
|
|||
return tenant; |
|||
} |
|||
|
|||
protected virtual async Task<TenantConfiguration> FindTenantAsync(string tenantIdOrName) |
|||
{ |
|||
if (Guid.TryParse(tenantIdOrName, out var parsedTenantId)) |
|||
{ |
|||
return await TenantStore.FindAsync(parsedTenantId); |
|||
} |
|||
else |
|||
{ |
|||
return await TenantStore.FindAsync(tenantIdOrName); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue