27 changed files with 96 additions and 670 deletions
@ -1,70 +0,0 @@ |
|||
using LINGYUN.Abp.Data.DbMigrator; |
|||
using LINGYUN.Abp.MicroService.MessageService.MultiTenancy; |
|||
using LINGYUN.Abp.Notifications; |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using Microsoft.Extensions.Logging; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.MessageService.Handlers.Distributed |
|||
{ |
|||
public class TenantSynchronizer : |
|||
IDistributedEventHandler<EntityCreatedEto<TenantEto>>, |
|||
IDistributedEventHandler<EntityUpdatedEto<TenantEto>>, |
|||
IDistributedEventHandler<EntityDeletedEto<TenantEto>>, |
|||
IDistributedEventHandler<TenantConnectionStringUpdatedEto>, |
|||
ITransientDependency |
|||
{ |
|||
protected ILogger<TenantSynchronizer> Logger { get; } |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
protected IUnitOfWorkManager UnitOfWorkManager { get; } |
|||
protected IDbSchemaMigrator DbSchemaMigrator { get; } |
|||
protected INotificationSender NotificationSender { get; } |
|||
protected ITenantConfigurationCache TenantConfigurationCache { get; } |
|||
protected INotificationSubscriptionManager NotificationSubscriptionManager { get; } |
|||
|
|||
public TenantSynchronizer( |
|||
ICurrentTenant currentTenant, |
|||
IDbSchemaMigrator dbSchemaMigrator, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
INotificationSender notificationSender, |
|||
ITenantConfigurationCache tenantConfigurationCache, |
|||
INotificationSubscriptionManager notificationSubscriptionManager, |
|||
ILogger<TenantSynchronizer> logger) |
|||
{ |
|||
Logger = logger; |
|||
|
|||
CurrentTenant = currentTenant; |
|||
DbSchemaMigrator = dbSchemaMigrator; |
|||
UnitOfWorkManager = unitOfWorkManager; |
|||
TenantConfigurationCache = tenantConfigurationCache; |
|||
|
|||
NotificationSender = notificationSender; |
|||
NotificationSubscriptionManager = notificationSubscriptionManager; |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityCreatedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityUpdatedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityDeletedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(TenantConnectionStringUpdatedEto eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.MessageService.MultiTenancy; |
|||
|
|||
public interface ITenantConfigurationCache |
|||
{ |
|||
Task RefreshAsync(); |
|||
|
|||
Task<List<TenantConfiguration>> GetTenantsAsync(); |
|||
} |
|||
@ -1,62 +0,0 @@ |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.MessageService.MultiTenancy; |
|||
|
|||
public class TenantConfigurationCache : ITenantConfigurationCache, ITransientDependency |
|||
{ |
|||
protected ITenantRepository TenantRepository { get; } |
|||
protected IDistributedCache<TenantConfigurationCacheItem> TenantCache { get; } |
|||
|
|||
public TenantConfigurationCache( |
|||
ITenantRepository tenantRepository, |
|||
IDistributedCache<TenantConfigurationCacheItem> tenantCache) |
|||
{ |
|||
TenantRepository = tenantRepository; |
|||
TenantCache = tenantCache; |
|||
} |
|||
|
|||
public async virtual Task RefreshAsync() |
|||
{ |
|||
var cacheKey = GetCacheKey(); |
|||
|
|||
await TenantCache.RemoveAsync(cacheKey); |
|||
} |
|||
|
|||
public async virtual Task<List<TenantConfiguration>> GetTenantsAsync() |
|||
{ |
|||
return (await GetForCacheItemAsync()).Tenants; |
|||
} |
|||
|
|||
protected async virtual Task<TenantConfigurationCacheItem> GetForCacheItemAsync() |
|||
{ |
|||
var cacheKey = GetCacheKey(); |
|||
var cacheItem = await TenantCache.GetAsync(cacheKey); |
|||
if (cacheItem == null) |
|||
{ |
|||
var allActiveTenants = await TenantRepository.GetListAsync(); |
|||
|
|||
cacheItem = new TenantConfigurationCacheItem( |
|||
allActiveTenants |
|||
.Where(t => t.IsActive) |
|||
.Select(t => new TenantConfiguration(t.Id, t.Name) |
|||
{ |
|||
IsActive = t.IsActive, |
|||
}).ToList()); |
|||
|
|||
await TenantCache.SetAsync(cacheKey, cacheItem); |
|||
} |
|||
|
|||
return cacheItem; |
|||
} |
|||
|
|||
protected virtual string GetCacheKey() |
|||
{ |
|||
return "_Abp_Tenant_Configuration"; |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.MessageService.MultiTenancy; |
|||
|
|||
[IgnoreMultiTenancy] |
|||
public class TenantConfigurationCacheItem |
|||
{ |
|||
public List<TenantConfiguration> Tenants { get; set; } |
|||
|
|||
public TenantConfigurationCacheItem() |
|||
{ |
|||
Tenants = new List<TenantConfiguration>(); |
|||
} |
|||
|
|||
public TenantConfigurationCacheItem(List<TenantConfiguration> tenants) |
|||
{ |
|||
Tenants = tenants; |
|||
} |
|||
} |
|||
@ -1,8 +0,0 @@ |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.PlatformService.MultiTenancy; |
|||
|
|||
public interface ITenantConfigurationCache |
|||
{ |
|||
Task<List<TenantConfiguration>> GetTenantsAsync(); |
|||
} |
|||
@ -1,47 +0,0 @@ |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.PlatformService.MultiTenancy; |
|||
|
|||
public class TenantConfigurationCache : ITenantConfigurationCache, ITransientDependency |
|||
{ |
|||
protected ITenantRepository TenantRepository { get; } |
|||
protected IDistributedCache<TenantConfigurationCacheItem> TenantCache { get; } |
|||
|
|||
public TenantConfigurationCache( |
|||
ITenantRepository tenantRepository, |
|||
IDistributedCache<TenantConfigurationCacheItem> tenantCache) |
|||
{ |
|||
TenantRepository = tenantRepository; |
|||
TenantCache = tenantCache; |
|||
} |
|||
|
|||
public async virtual Task<List<TenantConfiguration>> GetTenantsAsync() |
|||
{ |
|||
return (await GetForCacheItemAsync()).Tenants; |
|||
} |
|||
|
|||
protected async virtual Task<TenantConfigurationCacheItem> GetForCacheItemAsync() |
|||
{ |
|||
var cacheKey = "_Abp_Tenant_Configuration"; |
|||
var cacheItem = await TenantCache.GetAsync(cacheKey); |
|||
if (cacheItem == null) |
|||
{ |
|||
var allActiveTenants = await TenantRepository.GetListAsync(); |
|||
|
|||
cacheItem = new TenantConfigurationCacheItem( |
|||
allActiveTenants |
|||
.Where(t => t.IsActive) |
|||
.Select(t => new TenantConfiguration(t.Id, t.Name) |
|||
{ |
|||
IsActive = t.IsActive, |
|||
}).ToList()); |
|||
|
|||
await TenantCache.SetAsync(cacheKey, cacheItem); |
|||
} |
|||
|
|||
return cacheItem; |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.MicroService.PlatformService.MultiTenancy; |
|||
|
|||
[IgnoreMultiTenancy] |
|||
public class TenantConfigurationCacheItem |
|||
{ |
|||
public List<TenantConfiguration> Tenants { get; set; } |
|||
|
|||
public TenantConfigurationCacheItem() |
|||
{ |
|||
Tenants = new List<TenantConfiguration>(); |
|||
} |
|||
|
|||
public TenantConfigurationCacheItem(List<TenantConfiguration> tenants) |
|||
{ |
|||
Tenants = tenants; |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LINGYUN.Abp.Saas.Tenants; |
|||
|
|||
[Serializable] |
|||
[IgnoreMultiTenancy] |
|||
[CacheName("AbpSaasTenantsAll")] |
|||
public class TenantsCacheItem |
|||
{ |
|||
private const string CacheKeyFormat = "id:{0}"; |
|||
|
|||
public List<TenantConfiguration> Tenants { get; set; } |
|||
public TenantsCacheItem() |
|||
{ |
|||
|
|||
} |
|||
public TenantsCacheItem(List<TenantConfiguration> tenants) |
|||
{ |
|||
Tenants = tenants; |
|||
} |
|||
public static string CalculateCacheKey(bool includeDetails = false) |
|||
{ |
|||
return string.Format(CacheKeyFormat, includeDetails.ToString()); |
|||
} |
|||
} |
|||
@ -1,46 +0,0 @@ |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using LY.MicroService.Applications.Single.MultiTenancy; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LY.MicroService.Applications.Single.EventBus.Distributed |
|||
{ |
|||
public class TenantEventHandler : |
|||
IDistributedEventHandler<EntityCreatedEto<TenantEto>>, |
|||
IDistributedEventHandler<EntityUpdatedEto<TenantEto>>, |
|||
IDistributedEventHandler<EntityDeletedEto<TenantEto>>, |
|||
IDistributedEventHandler<TenantConnectionStringUpdatedEto>, |
|||
ITransientDependency |
|||
{ |
|||
protected ITenantConfigurationCache TenantConfigurationCache { get; } |
|||
|
|||
public TenantEventHandler( |
|||
ITenantConfigurationCache tenantConfigurationCache) |
|||
{ |
|||
TenantConfigurationCache = tenantConfigurationCache; |
|||
} |
|||
|
|||
[UnitOfWork] |
|||
public async virtual Task HandleEventAsync(EntityCreatedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityUpdatedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityDeletedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(TenantConnectionStringUpdatedEto eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.Applications.Single.MultiTenancy; |
|||
|
|||
public interface ITenantConfigurationCache |
|||
{ |
|||
Task RefreshAsync(); |
|||
|
|||
Task<List<TenantConfiguration>> GetTenantsAsync(); |
|||
} |
|||
@ -1,59 +0,0 @@ |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.Applications.Single.MultiTenancy; |
|||
|
|||
public class TenantConfigurationCache : ITenantConfigurationCache, ITransientDependency |
|||
{ |
|||
protected ITenantRepository TenantRepository { get; } |
|||
protected IDistributedCache<TenantConfigurationCacheItem> TenantCache { get; } |
|||
|
|||
public TenantConfigurationCache( |
|||
ITenantRepository tenantRepository, |
|||
IDistributedCache<TenantConfigurationCacheItem> tenantCache) |
|||
{ |
|||
TenantRepository = tenantRepository; |
|||
TenantCache = tenantCache; |
|||
} |
|||
|
|||
public async virtual Task RefreshAsync() |
|||
{ |
|||
var cacheKey = GetCacheKey(); |
|||
|
|||
await TenantCache.RemoveAsync(cacheKey); |
|||
} |
|||
|
|||
public async virtual Task<List<TenantConfiguration>> GetTenantsAsync() |
|||
{ |
|||
return (await GetForCacheItemAsync()).Tenants; |
|||
} |
|||
|
|||
protected async virtual Task<TenantConfigurationCacheItem> GetForCacheItemAsync() |
|||
{ |
|||
var cacheKey = GetCacheKey(); |
|||
var cacheItem = await TenantCache.GetAsync(cacheKey); |
|||
if (cacheItem == null) |
|||
{ |
|||
var allActiveTenants = await TenantRepository.GetListAsync(); |
|||
|
|||
cacheItem = new TenantConfigurationCacheItem( |
|||
allActiveTenants |
|||
.Where(t => t.IsActive) |
|||
.Select(t => new TenantConfiguration(t.Id, t.Name) |
|||
{ |
|||
IsActive = t.IsActive, |
|||
}).ToList()); |
|||
|
|||
await TenantCache.SetAsync(cacheKey, cacheItem); |
|||
} |
|||
|
|||
return cacheItem; |
|||
} |
|||
|
|||
protected virtual string GetCacheKey() |
|||
{ |
|||
return "_Abp_Tenant_Configuration"; |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.Applications.Single.MultiTenancy; |
|||
|
|||
[IgnoreMultiTenancy] |
|||
public class TenantConfigurationCacheItem |
|||
{ |
|||
public List<TenantConfiguration> Tenants { get; set; } |
|||
|
|||
public TenantConfigurationCacheItem() |
|||
{ |
|||
Tenants = new List<TenantConfiguration>(); |
|||
} |
|||
|
|||
public TenantConfigurationCacheItem(List<TenantConfiguration> tenants) |
|||
{ |
|||
Tenants = tenants; |
|||
} |
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.PlatformManagement.MultiTenancy; |
|||
|
|||
public interface ITenantConfigurationCache |
|||
{ |
|||
Task<List<TenantConfiguration>> GetTenantsAsync(); |
|||
} |
|||
@ -1,50 +0,0 @@ |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.PlatformManagement.MultiTenancy; |
|||
|
|||
public class TenantConfigurationCache : ITenantConfigurationCache, ITransientDependency |
|||
{ |
|||
protected ITenantRepository TenantRepository { get; } |
|||
protected IDistributedCache<TenantConfigurationCacheItem> TenantCache { get; } |
|||
|
|||
public TenantConfigurationCache( |
|||
ITenantRepository tenantRepository, |
|||
IDistributedCache<TenantConfigurationCacheItem> tenantCache) |
|||
{ |
|||
TenantRepository = tenantRepository; |
|||
TenantCache = tenantCache; |
|||
} |
|||
|
|||
public async virtual Task<List<TenantConfiguration>> GetTenantsAsync() |
|||
{ |
|||
return (await GetForCacheItemAsync()).Tenants; |
|||
} |
|||
|
|||
protected async virtual Task<TenantConfigurationCacheItem> GetForCacheItemAsync() |
|||
{ |
|||
var cacheKey = "_Abp_Tenant_Configuration"; |
|||
var cacheItem = await TenantCache.GetAsync(cacheKey); |
|||
if (cacheItem == null) |
|||
{ |
|||
var allActiveTenants = await TenantRepository.GetListAsync(); |
|||
|
|||
cacheItem = new TenantConfigurationCacheItem( |
|||
allActiveTenants |
|||
.Where(t => t.IsActive) |
|||
.Select(t => new TenantConfiguration(t.Id, t.Name) |
|||
{ |
|||
IsActive = t.IsActive, |
|||
}).ToList()); |
|||
|
|||
await TenantCache.SetAsync(cacheKey, cacheItem); |
|||
} |
|||
|
|||
return cacheItem; |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.PlatformManagement.MultiTenancy; |
|||
|
|||
[IgnoreMultiTenancy] |
|||
public class TenantConfigurationCacheItem |
|||
{ |
|||
public List<TenantConfiguration> Tenants { get; set; } |
|||
|
|||
public TenantConfigurationCacheItem() |
|||
{ |
|||
Tenants = new List<TenantConfiguration>(); |
|||
} |
|||
|
|||
public TenantConfigurationCacheItem(List<TenantConfiguration> tenants) |
|||
{ |
|||
Tenants = tenants; |
|||
} |
|||
} |
|||
@ -1,70 +0,0 @@ |
|||
using LINGYUN.Abp.Data.DbMigrator; |
|||
using LINGYUN.Abp.Notifications; |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using LY.MicroService.RealtimeMessage.MultiTenancy; |
|||
using Microsoft.Extensions.Logging; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events.Distributed; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace LY.MicroService.RealtimeMessage.EventBus.Distributed |
|||
{ |
|||
public class TenantSynchronizer : |
|||
IDistributedEventHandler<EntityCreatedEto<TenantEto>>, |
|||
IDistributedEventHandler<EntityUpdatedEto<TenantEto>>, |
|||
IDistributedEventHandler<EntityDeletedEto<TenantEto>>, |
|||
IDistributedEventHandler<TenantConnectionStringUpdatedEto>, |
|||
ITransientDependency |
|||
{ |
|||
protected ILogger<TenantSynchronizer> Logger { get; } |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
protected IUnitOfWorkManager UnitOfWorkManager { get; } |
|||
protected IDbSchemaMigrator DbSchemaMigrator { get; } |
|||
protected INotificationSender NotificationSender { get; } |
|||
protected ITenantConfigurationCache TenantConfigurationCache { get; } |
|||
protected INotificationSubscriptionManager NotificationSubscriptionManager { get; } |
|||
|
|||
public TenantSynchronizer( |
|||
ICurrentTenant currentTenant, |
|||
IDbSchemaMigrator dbSchemaMigrator, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
INotificationSender notificationSender, |
|||
ITenantConfigurationCache tenantConfigurationCache, |
|||
INotificationSubscriptionManager notificationSubscriptionManager, |
|||
ILogger<TenantSynchronizer> logger) |
|||
{ |
|||
Logger = logger; |
|||
|
|||
CurrentTenant = currentTenant; |
|||
DbSchemaMigrator = dbSchemaMigrator; |
|||
UnitOfWorkManager = unitOfWorkManager; |
|||
TenantConfigurationCache = tenantConfigurationCache; |
|||
|
|||
NotificationSender = notificationSender; |
|||
NotificationSubscriptionManager = notificationSubscriptionManager; |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityCreatedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityUpdatedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(EntityDeletedEto<TenantEto> eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
|
|||
public async virtual Task HandleEventAsync(TenantConnectionStringUpdatedEto eventData) |
|||
{ |
|||
await TenantConfigurationCache.RefreshAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.RealtimeMessage.MultiTenancy; |
|||
|
|||
public interface ITenantConfigurationCache |
|||
{ |
|||
Task RefreshAsync(); |
|||
|
|||
Task<List<TenantConfiguration>> GetTenantsAsync(); |
|||
} |
|||
@ -1,62 +0,0 @@ |
|||
using LINGYUN.Abp.Saas.Tenants; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.RealtimeMessage.MultiTenancy; |
|||
|
|||
public class TenantConfigurationCache : ITenantConfigurationCache, ITransientDependency |
|||
{ |
|||
protected ITenantRepository TenantRepository { get; } |
|||
protected IDistributedCache<TenantConfigurationCacheItem> TenantCache { get; } |
|||
|
|||
public TenantConfigurationCache( |
|||
ITenantRepository tenantRepository, |
|||
IDistributedCache<TenantConfigurationCacheItem> tenantCache) |
|||
{ |
|||
TenantRepository = tenantRepository; |
|||
TenantCache = tenantCache; |
|||
} |
|||
|
|||
public async virtual Task RefreshAsync() |
|||
{ |
|||
var cacheKey = GetCacheKey(); |
|||
|
|||
await TenantCache.RemoveAsync(cacheKey); |
|||
} |
|||
|
|||
public async virtual Task<List<TenantConfiguration>> GetTenantsAsync() |
|||
{ |
|||
return (await GetForCacheItemAsync()).Tenants; |
|||
} |
|||
|
|||
protected async virtual Task<TenantConfigurationCacheItem> GetForCacheItemAsync() |
|||
{ |
|||
var cacheKey = GetCacheKey(); |
|||
var cacheItem = await TenantCache.GetAsync(cacheKey); |
|||
if (cacheItem == null) |
|||
{ |
|||
var allActiveTenants = await TenantRepository.GetListAsync(); |
|||
|
|||
cacheItem = new TenantConfigurationCacheItem( |
|||
allActiveTenants |
|||
.Where(t => t.IsActive) |
|||
.Select(t => new TenantConfiguration(t.Id, t.Name) |
|||
{ |
|||
IsActive = t.IsActive, |
|||
}).ToList()); |
|||
|
|||
await TenantCache.SetAsync(cacheKey, cacheItem); |
|||
} |
|||
|
|||
return cacheItem; |
|||
} |
|||
|
|||
protected virtual string GetCacheKey() |
|||
{ |
|||
return "_Abp_Tenant_Configuration"; |
|||
} |
|||
} |
|||
@ -1,20 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace LY.MicroService.RealtimeMessage.MultiTenancy; |
|||
|
|||
[IgnoreMultiTenancy] |
|||
public class TenantConfigurationCacheItem |
|||
{ |
|||
public List<TenantConfiguration> Tenants { get; set; } |
|||
|
|||
public TenantConfigurationCacheItem() |
|||
{ |
|||
Tenants = new List<TenantConfiguration>(); |
|||
} |
|||
|
|||
public TenantConfigurationCacheItem(List<TenantConfiguration> tenants) |
|||
{ |
|||
Tenants = tenants; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue