Browse Source

Cancel changes to the tenant module.

pull/2466/head
maliming 7 years ago
parent
commit
a72fb4e567
  1. 56
      framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs
  2. 4
      framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantStore.cs
  3. 3
      framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantConnectionStringResolver.cs
  4. 10
      modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/ITenantRepository.cs
  5. 28
      modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantStore.cs

56
framework/src/Volo.Abp.AspNetCore.Mvc.Client/Volo/Abp/AspNetCore/Mvc/Client/RemoteTenantStore.cs

@ -83,6 +83,62 @@ namespace Volo.Abp.AspNetCore.Mvc.Client
return tenantConfiguration;
}
public TenantConfiguration Find(string name)
{
var cacheKey = CreateCacheKey(name);
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is TenantConfiguration tenantConfiguration)
{
return tenantConfiguration;
}
tenantConfiguration = Cache.GetOrAdd(
cacheKey,
() => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByNameAsync(name))),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow =
TimeSpan.FromMinutes(5) //TODO: Should be configurable.
}
);
if (httpContext != null)
{
httpContext.Items[cacheKey] = tenantConfiguration;
}
return tenantConfiguration;
}
public TenantConfiguration Find(Guid id)
{
var cacheKey = CreateCacheKey(id);
var httpContext = HttpContextAccessor?.HttpContext;
if (httpContext != null && httpContext.Items[cacheKey] is TenantConfiguration tenantConfiguration)
{
return tenantConfiguration;
}
tenantConfiguration = Cache.GetOrAdd(
cacheKey,
() => AsyncHelper.RunSync(async () => CreateTenantConfiguration(await Proxy.Service.FindTenantByIdAsync(id))),
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow =
TimeSpan.FromMinutes(5) //TODO: Should be configurable.
}
);
if (httpContext != null)
{
httpContext.Items[cacheKey] = tenantConfiguration;
}
return tenantConfiguration;
}
protected virtual TenantConfiguration CreateTenantConfiguration(FindTenantResultDto tenantResultDto)
{
if (!tenantResultDto.Success || tenantResultDto.TenantId == null)

4
framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/ITenantStore.cs

@ -8,5 +8,9 @@ namespace Volo.Abp.MultiTenancy
Task<TenantConfiguration> FindAsync(string name);
Task<TenantConfiguration> FindAsync(Guid id);
TenantConfiguration Find(string name);
TenantConfiguration Find(Guid id);
}
}

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

@ -4,7 +4,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading;
namespace Volo.Abp.MultiTenancy
{
@ -38,7 +37,7 @@ namespace Volo.Abp.MultiTenancy
.ServiceProvider
.GetRequiredService<ITenantStore>();
var tenant = AsyncHelper.RunSync(() => tenantStore.FindAsync(_currentTenant.Id.Value));
var tenant = tenantStore.Find(_currentTenant.Id.Value);
if (tenant?.ConnectionStrings == null)
{

10
modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/ITenantRepository.cs

@ -13,6 +13,16 @@ namespace Volo.Abp.TenantManagement
bool includeDetails = true,
CancellationToken cancellationToken = default);
Tenant FindByName(
string name,
bool includeDetails = true
);
Tenant FindById(
Guid id,
bool includeDetails = true
);
Task<List<Tenant>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,

28
modules/tenant-management/src/Volo.Abp.TenantManagement.Domain/Volo/Abp/TenantManagement/TenantStore.cs

@ -51,5 +51,33 @@ namespace Volo.Abp.TenantManagement
return _objectMapper.Map<Tenant, TenantConfiguration>(tenant);
}
}
public TenantConfiguration Find(string name)
{
using (_currentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities!
{
var tenant = _tenantRepository.FindByName(name);
if (tenant == null)
{
return null;
}
return _objectMapper.Map<Tenant, TenantConfiguration>(tenant);
}
}
public TenantConfiguration Find(Guid id)
{
using (_currentTenant.Change(null)) //TODO: No need this if we can implement to define host side (or tenant-independent) entities!
{
var tenant = _tenantRepository.FindById(id);
if (tenant == null)
{
return null;
}
return _objectMapper.Map<Tenant, TenantConfiguration>(tenant);
}
}
}
}

Loading…
Cancel
Save