diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/Handlers/Distributed/NotificationEventHandler.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/Handlers/Distributed/NotificationEventHandler.cs index 8ba419705..29c23b3dc 100644 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/Handlers/Distributed/NotificationEventHandler.cs +++ b/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/Handlers/Distributed/NotificationEventHandler.cs @@ -1,5 +1,4 @@ using LINGYUN.Abp.MicroService.MessageService.BackgroundJobs; -using LINGYUN.Abp.MicroService.MessageService.MultiTenancy; using LINGYUN.Abp.Notifications; using LINGYUN.Abp.Notifications.Templating; using Microsoft.Extensions.Localization; @@ -57,9 +56,9 @@ namespace LINGYUN.Abp.MicroService.MessageService.Handlers.Distributed /// protected ICurrentTenant CurrentTenant { get; } /// - /// Reference to . + /// Reference to . /// - protected ITenantConfigurationCache TenantConfigurationCache { get; } + protected ITenantStore TenantStore { get; } /// /// Reference to . /// @@ -108,7 +107,7 @@ namespace LINGYUN.Abp.MicroService.MessageService.Handlers.Distributed IClock clock, ICurrentTenant currentTenant, ISettingProvider settingProvider, - ITenantConfigurationCache tenantConfigurationCache, + ITenantStore tenantStore, IJsonSerializer jsonSerializer, ITemplateRenderer templateRenderer, IBackgroundJobManager backgroundJobManager, @@ -123,7 +122,7 @@ namespace LINGYUN.Abp.MicroService.MessageService.Handlers.Distributed { Clock = clock; Options = options.Value; - TenantConfigurationCache = tenantConfigurationCache; + TenantStore = tenantStore; CurrentTenant = currentTenant; SettingProvider = settingProvider; JsonSerializer = jsonSerializer; @@ -165,7 +164,7 @@ namespace LINGYUN.Abp.MicroService.MessageService.Handlers.Distributed { await SendToTenantAsync(null, notification, eventData, result); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { @@ -202,7 +201,7 @@ namespace LINGYUN.Abp.MicroService.MessageService.Handlers.Distributed { await SendToTenantAsync(null, notification, eventData); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/Handlers/Distributed/TenantSynchronizer.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/Handlers/Distributed/TenantSynchronizer.cs deleted file mode 100644 index bfa3281be..000000000 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/Handlers/Distributed/TenantSynchronizer.cs +++ /dev/null @@ -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>, - IDistributedEventHandler>, - IDistributedEventHandler>, - IDistributedEventHandler, - ITransientDependency - { - protected ILogger 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 logger) - { - Logger = logger; - - CurrentTenant = currentTenant; - DbSchemaMigrator = dbSchemaMigrator; - UnitOfWorkManager = unitOfWorkManager; - TenantConfigurationCache = tenantConfigurationCache; - - NotificationSender = notificationSender; - NotificationSubscriptionManager = notificationSubscriptionManager; - } - - public async virtual Task HandleEventAsync(EntityCreatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(EntityUpdatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(EntityDeletedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(TenantConnectionStringUpdatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - } -} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/ITenantConfigurationCache.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/ITenantConfigurationCache.cs deleted file mode 100644 index f9f8d02a3..000000000 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/ITenantConfigurationCache.cs +++ /dev/null @@ -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> GetTenantsAsync(); -} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/TenantConfigurationCache.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/TenantConfigurationCache.cs deleted file mode 100644 index ab9e4ec67..000000000 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/TenantConfigurationCache.cs +++ /dev/null @@ -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 TenantCache { get; } - - public TenantConfigurationCache( - ITenantRepository tenantRepository, - IDistributedCache tenantCache) - { - TenantRepository = tenantRepository; - TenantCache = tenantCache; - } - - public async virtual Task RefreshAsync() - { - var cacheKey = GetCacheKey(); - - await TenantCache.RemoveAsync(cacheKey); - } - - public async virtual Task> GetTenantsAsync() - { - return (await GetForCacheItemAsync()).Tenants; - } - - protected async virtual Task 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"; - } -} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/TenantConfigurationCacheItem.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/TenantConfigurationCacheItem.cs deleted file mode 100644 index 8504783cb..000000000 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.MessageService/MultiTenancy/TenantConfigurationCacheItem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.MultiTenancy; - -namespace LINGYUN.Abp.MicroService.MessageService.MultiTenancy; - -[IgnoreMultiTenancy] -public class TenantConfigurationCacheItem -{ - public List Tenants { get; set; } - - public TenantConfigurationCacheItem() - { - Tenants = new List(); - } - - public TenantConfigurationCacheItem(List tenants) - { - Tenants = tenants; - } -} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs index 33625a332..ced3b33f4 100644 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs +++ b/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs @@ -1,5 +1,4 @@ using LINGYUN.Abp.BlobManagement; -using LINGYUN.Abp.MicroService.PlatformService.MultiTenancy; using Microsoft.Extensions.Options; using Volo.Abp.BackgroundWorkers; using Volo.Abp.DistributedLocking; @@ -12,7 +11,7 @@ public class BlobTempCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase { protected ICurrentTenant CurrentTenant { get; } protected IAbpDistributedLock DistributedLock { get; } - protected ITenantConfigurationCache TenantConfigurationCache { get; } + protected ITenantStore TenantStore { get; } public BlobTempCleanupBackgroundWorker( AbpAsyncTimer timer, @@ -20,12 +19,12 @@ public class BlobTempCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase IOptionsMonitor cleanupOptions, IAbpDistributedLock distributedLock, ICurrentTenant currentTenant, - ITenantConfigurationCache tenantConfigurationCache) + ITenantStore tenantStore) : base(timer, serviceScopeFactory) { CurrentTenant = currentTenant; DistributedLock = distributedLock; - TenantConfigurationCache = tenantConfigurationCache; + TenantStore = tenantStore; timer.Period = cleanupOptions.CurrentValue.CleanupPeriod; } @@ -41,7 +40,7 @@ public class BlobTempCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase { await ExecuteCleanService(workerContext); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/ITenantConfigurationCache.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/ITenantConfigurationCache.cs deleted file mode 100644 index 1b6c5cf69..000000000 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/ITenantConfigurationCache.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Volo.Abp.MultiTenancy; - -namespace LINGYUN.Abp.MicroService.PlatformService.MultiTenancy; - -public interface ITenantConfigurationCache -{ - Task> GetTenantsAsync(); -} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/TenantConfigurationCache.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/TenantConfigurationCache.cs deleted file mode 100644 index bd881db3d..000000000 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/TenantConfigurationCache.cs +++ /dev/null @@ -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 TenantCache { get; } - - public TenantConfigurationCache( - ITenantRepository tenantRepository, - IDistributedCache tenantCache) - { - TenantRepository = tenantRepository; - TenantCache = tenantCache; - } - - public async virtual Task> GetTenantsAsync() - { - return (await GetForCacheItemAsync()).Tenants; - } - - protected async virtual Task 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; - } -} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/TenantConfigurationCacheItem.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/TenantConfigurationCacheItem.cs deleted file mode 100644 index 8bd0abd3d..000000000 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.PlatformService/MultiTenancy/TenantConfigurationCacheItem.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Volo.Abp.MultiTenancy; - -namespace LINGYUN.Abp.MicroService.PlatformService.MultiTenancy; - -[IgnoreMultiTenancy] -public class TenantConfigurationCacheItem -{ - public List Tenants { get; set; } - - public TenantConfigurationCacheItem() - { - Tenants = new List(); - } - - public TenantConfigurationCacheItem(List tenants) - { - Tenants = tenants; - } -} diff --git a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs index e18b7e4ae..aa5a3d167 100644 --- a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs +++ b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantCacheItemInvalidator.cs @@ -17,11 +17,15 @@ public class TenantCacheItemInvalidator : ILocalEventHandler>, ITransientDependency { - protected IDistributedCache Cache { get; } + protected IDistributedCache TenantCache { get; } + protected IDistributedCache TenantsCache { get; } - public TenantCacheItemInvalidator(IDistributedCache cache) + public TenantCacheItemInvalidator( + IDistributedCache tenantCache, + IDistributedCache tenantsCache) { - Cache = cache; + TenantCache = tenantCache; + TenantsCache = tenantsCache; } public async virtual Task HandleEventAsync(EntityCreatedEto eto) @@ -46,7 +50,7 @@ public class TenantCacheItemInvalidator : protected async virtual Task RemoveTenantCache(Guid tenantId, string tenantName = null) { - var keys = new string[] + var removeTenantKeys = new string[] { TenantCacheItem.CalculateCacheKey(null, tenantName), TenantCacheItem.CalculateCacheKey(tenantId, null), @@ -55,6 +59,13 @@ public class TenantCacheItemInvalidator : // 同时移除租户版本缓存 EditionCacheItem.CalculateCacheKey(tenantId) }; - await Cache.RemoveManyAsync(keys, considerUow: true); + await TenantCache.RemoveManyAsync(removeTenantKeys, considerUow: true); + + var removeTenantsKeys = new string[] + { + TenantsCacheItem.CalculateCacheKey(true), + TenantsCacheItem.CalculateCacheKey(false) + }; + await TenantsCache.RemoveManyAsync(removeTenantsKeys, considerUow: true); } } diff --git a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantStore.cs b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantStore.cs index fcc2ff27e..fe254027e 100644 --- a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantStore.cs +++ b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantStore.cs @@ -1,7 +1,7 @@ -using System; +using JetBrains.Annotations; +using System; using System.Collections.Generic; using System.Threading.Tasks; -using JetBrains.Annotations; using Volo.Abp; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; @@ -15,18 +15,21 @@ public class TenantStore : ITenantStore, ITransientDependency protected ITenantRepository TenantRepository { get; } protected IObjectMapper ObjectMapper { get; } protected ICurrentTenant CurrentTenant { get; } - protected IDistributedCache Cache { get; } + protected IDistributedCache TenantCache { get; } + protected IDistributedCache TenantsCache { get; } public TenantStore( ITenantRepository tenantRepository, IObjectMapper objectMapper, ICurrentTenant currentTenant, - IDistributedCache cache) + IDistributedCache tenantCache, + IDistributedCache tenantsCache) { TenantRepository = tenantRepository; ObjectMapper = objectMapper; CurrentTenant = currentTenant; - Cache = cache; + TenantCache = tenantCache; + TenantsCache = tenantsCache; } public async virtual Task FindAsync(string name) @@ -41,8 +44,16 @@ public class TenantStore : ITenantStore, ITransientDependency public async virtual Task> GetListAsync(bool includeDetails = false) { - return ObjectMapper.Map, List>( - await TenantRepository.GetListAsync(includeDetails)); + var cacheKey = TenantsCacheItem.CalculateCacheKey(includeDetails); + var cacheItem = await TenantsCache.GetAsync(cacheKey); + if (cacheItem == null) + { + var tenants = await TenantRepository.GetListAsync(includeDetails); + var tenantConfiurations = ObjectMapper.Map, List>(tenants); + cacheItem = new TenantsCacheItem(tenantConfiurations); + await TenantsCache.SetAsync(cacheKey, cacheItem, considerUow: true); + } + return [.. cacheItem.Tenants]; } [Obsolete("Use FindAsync method.")] @@ -61,7 +72,7 @@ public class TenantStore : ITenantStore, ITransientDependency { var cacheKey = CalculateCacheKey(id, name); - var cacheItem = await Cache.GetAsync(cacheKey, considerUow: true); + var cacheItem = await TenantCache.GetAsync(cacheKey, considerUow: true); if (cacheItem != null) { return cacheItem; @@ -92,7 +103,7 @@ public class TenantStore : ITenantStore, ITransientDependency { var tenantConfiguration = tenant != null ? ObjectMapper.Map(tenant) : null; var cacheItem = new TenantCacheItem(tenantConfiguration); - await Cache.SetAsync(cacheKey, cacheItem, considerUow: true); + await TenantCache.SetAsync(cacheKey, cacheItem, considerUow: true); return cacheItem; } @@ -101,7 +112,7 @@ public class TenantStore : ITenantStore, ITransientDependency { var cacheKey = CalculateCacheKey(id, name); - var cacheItem = Cache.Get(cacheKey, considerUow: true); + var cacheItem = TenantCache.Get(cacheKey, considerUow: true); if (cacheItem != null) { return cacheItem; @@ -133,7 +144,7 @@ public class TenantStore : ITenantStore, ITransientDependency { var tenantConfiguration = tenant != null ? ObjectMapper.Map(tenant) : null; var cacheItem = new TenantCacheItem(tenantConfiguration); - Cache.Set(cacheKey, cacheItem, considerUow: true); + TenantCache.Set(cacheKey, cacheItem, considerUow: true); return cacheItem; } diff --git a/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantsCacheItem.cs b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantsCacheItem.cs new file mode 100644 index 000000000..de4308691 --- /dev/null +++ b/aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain/LINGYUN/Abp/Saas/Tenants/TenantsCacheItem.cs @@ -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 Tenants { get; set; } + public TenantsCacheItem() + { + + } + public TenantsCacheItem(List tenants) + { + Tenants = tenants; + } + public static string CalculateCacheKey(bool includeDetails = false) + { + return string.Format(CacheKeyFormat, includeDetails.ToString()); + } +} diff --git a/aspnet-core/services/LY.MicroService.Applications.Single/EventBus/Distributed/NotificationEventHandler.cs b/aspnet-core/services/LY.MicroService.Applications.Single/EventBus/Distributed/NotificationEventHandler.cs index 9e163e427..804aba971 100644 --- a/aspnet-core/services/LY.MicroService.Applications.Single/EventBus/Distributed/NotificationEventHandler.cs +++ b/aspnet-core/services/LY.MicroService.Applications.Single/EventBus/Distributed/NotificationEventHandler.cs @@ -1,7 +1,4 @@ -using LINGYUN.Abp.Notifications; -using LINGYUN.Abp.Notifications.Templating; -using LY.MicroService.Applications.Single.BackgroundJobs; -using LY.MicroService.Applications.Single.MultiTenancy; +using LY.MicroService.Applications.Single.BackgroundJobs; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -9,9 +6,6 @@ using System.Globalization; using Volo.Abp.BackgroundJobs; using Volo.Abp.DependencyInjection; using Volo.Abp.EventBus.Distributed; -using Volo.Abp.Json; -using Volo.Abp.Localization; -using Volo.Abp.MultiTenancy; using Volo.Abp.TextTemplating; using Volo.Abp.Timing; using Volo.Abp.Uow; @@ -47,9 +41,9 @@ namespace LY.MicroService.Applications.Single.EventBus.Distributed /// protected ICurrentTenant CurrentTenant { get; } /// - /// Reference to . + /// Reference to . /// - protected ITenantConfigurationCache TenantConfigurationCache { get; } + protected ITenantStore TenantStore { get; } /// /// Reference to . /// @@ -97,7 +91,7 @@ namespace LY.MicroService.Applications.Single.EventBus.Distributed public NotificationEventHandler( IClock clock, ICurrentTenant currentTenant, - ITenantConfigurationCache tenantConfigurationCache, + ITenantStore tenantStore, IJsonSerializer jsonSerializer, ITemplateRenderer templateRenderer, IBackgroundJobManager backgroundJobManager, @@ -112,7 +106,7 @@ namespace LY.MicroService.Applications.Single.EventBus.Distributed { Clock = clock; Options = options.Value; - TenantConfigurationCache = tenantConfigurationCache; + TenantStore = tenantStore; CurrentTenant = currentTenant; JsonSerializer = jsonSerializer; TemplateRenderer = templateRenderer; @@ -152,7 +146,7 @@ namespace LY.MicroService.Applications.Single.EventBus.Distributed { await SendToTenantAsync(null, notification, eventData, result); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { @@ -182,7 +176,7 @@ namespace LY.MicroService.Applications.Single.EventBus.Distributed { await SendToTenantAsync(null, notification, eventData); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { diff --git a/aspnet-core/services/LY.MicroService.Applications.Single/EventBus/Distributed/TenantEventHandler.cs b/aspnet-core/services/LY.MicroService.Applications.Single/EventBus/Distributed/TenantEventHandler.cs deleted file mode 100644 index 325a36bd0..000000000 --- a/aspnet-core/services/LY.MicroService.Applications.Single/EventBus/Distributed/TenantEventHandler.cs +++ /dev/null @@ -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>, - IDistributedEventHandler>, - IDistributedEventHandler>, - IDistributedEventHandler, - ITransientDependency - { - protected ITenantConfigurationCache TenantConfigurationCache { get; } - - public TenantEventHandler( - ITenantConfigurationCache tenantConfigurationCache) - { - TenantConfigurationCache = tenantConfigurationCache; - } - - [UnitOfWork] - public async virtual Task HandleEventAsync(EntityCreatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(EntityUpdatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(EntityDeletedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(TenantConnectionStringUpdatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - } -} diff --git a/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/ITenantConfigurationCache.cs b/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/ITenantConfigurationCache.cs deleted file mode 100644 index fce53a23b..000000000 --- a/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/ITenantConfigurationCache.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Volo.Abp.MultiTenancy; - -namespace LY.MicroService.Applications.Single.MultiTenancy; - -public interface ITenantConfigurationCache -{ - Task RefreshAsync(); - - Task> GetTenantsAsync(); -} diff --git a/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/TenantConfigurationCache.cs b/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/TenantConfigurationCache.cs deleted file mode 100644 index bf5c7f017..000000000 --- a/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/TenantConfigurationCache.cs +++ /dev/null @@ -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 TenantCache { get; } - - public TenantConfigurationCache( - ITenantRepository tenantRepository, - IDistributedCache tenantCache) - { - TenantRepository = tenantRepository; - TenantCache = tenantCache; - } - - public async virtual Task RefreshAsync() - { - var cacheKey = GetCacheKey(); - - await TenantCache.RemoveAsync(cacheKey); - } - - public async virtual Task> GetTenantsAsync() - { - return (await GetForCacheItemAsync()).Tenants; - } - - protected async virtual Task 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"; - } -} diff --git a/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/TenantConfigurationCacheItem.cs b/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/TenantConfigurationCacheItem.cs deleted file mode 100644 index cc7a2674a..000000000 --- a/aspnet-core/services/LY.MicroService.Applications.Single/MultiTenancy/TenantConfigurationCacheItem.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Volo.Abp.MultiTenancy; - -namespace LY.MicroService.Applications.Single.MultiTenancy; - -[IgnoreMultiTenancy] -public class TenantConfigurationCacheItem -{ - public List Tenants { get; set; } - - public TenantConfigurationCacheItem() - { - Tenants = new List(); - } - - public TenantConfigurationCacheItem(List tenants) - { - Tenants = tenants; - } -} diff --git a/aspnet-core/services/LY.MicroService.Applications.Single/appsettings.json b/aspnet-core/services/LY.MicroService.Applications.Single/appsettings.json index 85418946b..f17c7dd52 100644 --- a/aspnet-core/services/LY.MicroService.Applications.Single/appsettings.json +++ b/aspnet-core/services/LY.MicroService.Applications.Single/appsettings.json @@ -36,7 +36,8 @@ "Override": { "System": "Warning", "Microsoft": "Warning", - "DotNetCore": "Information" + "DotNetCore": "Information", + "LINGYUN.Abp.BlobManagement": "Debug" } }, "Enrich": [ "FromLogContext", "WithProcessId", "WithThreadId", "WithEnvironmentName", "WithMachineName", "WithApplicationName", "WithUniqueId" ], diff --git a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs b/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs index ae121100d..d7b279ac0 100644 --- a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs +++ b/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/BackgroundWorkers/BlobTempCleanupBackgroundWorker.cs @@ -1,8 +1,8 @@ using LINGYUN.Abp.BlobManagement; -using LY.MicroService.PlatformManagement.MultiTenancy; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using System.Linq; using System.Threading.Tasks; using Volo.Abp.BackgroundWorkers; using Volo.Abp.DistributedLocking; @@ -13,9 +13,9 @@ namespace LY.MicroService.PlatformManagement.BackgroundWorkers; public class BlobTempCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase { + protected ITenantStore TenantStore { get; } protected ICurrentTenant CurrentTenant { get; } protected IAbpDistributedLock DistributedLock { get; } - protected ITenantConfigurationCache TenantConfigurationCache { get; } public BlobTempCleanupBackgroundWorker( AbpAsyncTimer timer, @@ -23,12 +23,12 @@ public class BlobTempCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase IOptionsMonitor cleanupOptions, IAbpDistributedLock distributedLock, ICurrentTenant currentTenant, - ITenantConfigurationCache tenantConfigurationCache) + ITenantStore tenantStore) : base(timer, serviceScopeFactory) { + TenantStore = tenantStore; CurrentTenant = currentTenant; DistributedLock = distributedLock; - TenantConfigurationCache = tenantConfigurationCache; timer.Period = cleanupOptions.CurrentValue.CleanupPeriod; } @@ -44,7 +44,7 @@ public class BlobTempCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase { await ExecuteCleanService(workerContext); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { diff --git a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/ITenantConfigurationCache.cs b/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/ITenantConfigurationCache.cs deleted file mode 100644 index 7b6736aa0..000000000 --- a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/ITenantConfigurationCache.cs +++ /dev/null @@ -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> GetTenantsAsync(); -} diff --git a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/TenantConfigurationCache.cs b/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/TenantConfigurationCache.cs deleted file mode 100644 index 91d1e6fe1..000000000 --- a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/TenantConfigurationCache.cs +++ /dev/null @@ -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 TenantCache { get; } - - public TenantConfigurationCache( - ITenantRepository tenantRepository, - IDistributedCache tenantCache) - { - TenantRepository = tenantRepository; - TenantCache = tenantCache; - } - - public async virtual Task> GetTenantsAsync() - { - return (await GetForCacheItemAsync()).Tenants; - } - - protected async virtual Task 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; - } -} diff --git a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/TenantConfigurationCacheItem.cs b/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/TenantConfigurationCacheItem.cs deleted file mode 100644 index 7925c4aa7..000000000 --- a/aspnet-core/services/LY.MicroService.PlatformManagement.HttpApi.Host/MultiTenancy/TenantConfigurationCacheItem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.MultiTenancy; - -namespace LY.MicroService.PlatformManagement.MultiTenancy; - -[IgnoreMultiTenancy] -public class TenantConfigurationCacheItem -{ - public List Tenants { get; set; } - - public TenantConfigurationCacheItem() - { - Tenants = new List(); - } - - public TenantConfigurationCacheItem(List tenants) - { - Tenants = tenants; - } -} diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs index 7805f9ec3..8253b7b31 100644 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs @@ -1,7 +1,6 @@ using LINGYUN.Abp.Notifications; using LINGYUN.Abp.Notifications.Templating; using LY.MicroService.RealtimeMessage.BackgroundJobs; -using LY.MicroService.RealtimeMessage.MultiTenancy; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -57,9 +56,9 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed /// protected ICurrentTenant CurrentTenant { get; } /// - /// Reference to . + /// Reference to . /// - protected ITenantConfigurationCache TenantConfigurationCache { get; } + protected ITenantStore TenantStore { get; } /// /// Reference to . /// @@ -108,7 +107,7 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed IClock clock, ICurrentTenant currentTenant, ISettingProvider settingProvider, - ITenantConfigurationCache tenantConfigurationCache, + ITenantStore tenantStore, IJsonSerializer jsonSerializer, ITemplateRenderer templateRenderer, IBackgroundJobManager backgroundJobManager, @@ -123,7 +122,7 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed { Clock = clock; Options = options.Value; - TenantConfigurationCache = tenantConfigurationCache; + TenantStore = tenantStore; CurrentTenant = currentTenant; SettingProvider = settingProvider; JsonSerializer = jsonSerializer; @@ -165,7 +164,7 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed { await SendToTenantAsync(null, notification, eventData, result); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { @@ -202,7 +201,7 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed { await SendToTenantAsync(null, notification, eventData); - var allActiveTenants = await TenantConfigurationCache.GetTenantsAsync(); + var allActiveTenants = (await TenantStore.GetListAsync()).Where(x => x.IsActive); foreach (var activeTenant in allActiveTenants) { diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/TenantSynchronizer.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/TenantSynchronizer.cs deleted file mode 100644 index acd86429c..000000000 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/TenantSynchronizer.cs +++ /dev/null @@ -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>, - IDistributedEventHandler>, - IDistributedEventHandler>, - IDistributedEventHandler, - ITransientDependency - { - protected ILogger 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 logger) - { - Logger = logger; - - CurrentTenant = currentTenant; - DbSchemaMigrator = dbSchemaMigrator; - UnitOfWorkManager = unitOfWorkManager; - TenantConfigurationCache = tenantConfigurationCache; - - NotificationSender = notificationSender; - NotificationSubscriptionManager = notificationSubscriptionManager; - } - - public async virtual Task HandleEventAsync(EntityCreatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(EntityUpdatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(EntityDeletedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - - public async virtual Task HandleEventAsync(TenantConnectionStringUpdatedEto eventData) - { - await TenantConfigurationCache.RefreshAsync(); - } - } -} diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/ITenantConfigurationCache.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/ITenantConfigurationCache.cs deleted file mode 100644 index 0706cb924..000000000 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/ITenantConfigurationCache.cs +++ /dev/null @@ -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> GetTenantsAsync(); -} diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/TenantConfigurationCache.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/TenantConfigurationCache.cs deleted file mode 100644 index df197c6ae..000000000 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/TenantConfigurationCache.cs +++ /dev/null @@ -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 TenantCache { get; } - - public TenantConfigurationCache( - ITenantRepository tenantRepository, - IDistributedCache tenantCache) - { - TenantRepository = tenantRepository; - TenantCache = tenantCache; - } - - public async virtual Task RefreshAsync() - { - var cacheKey = GetCacheKey(); - - await TenantCache.RemoveAsync(cacheKey); - } - - public async virtual Task> GetTenantsAsync() - { - return (await GetForCacheItemAsync()).Tenants; - } - - protected async virtual Task 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"; - } -} diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/TenantConfigurationCacheItem.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/TenantConfigurationCacheItem.cs deleted file mode 100644 index 7c2b77e2c..000000000 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/MultiTenancy/TenantConfigurationCacheItem.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using Volo.Abp.MultiTenancy; - -namespace LY.MicroService.RealtimeMessage.MultiTenancy; - -[IgnoreMultiTenancy] -public class TenantConfigurationCacheItem -{ - public List Tenants { get; set; } - - public TenantConfigurationCacheItem() - { - Tenants = new List(); - } - - public TenantConfigurationCacheItem(List tenants) - { - Tenants = tenants; - } -}