Browse Source

Merge pull request #22 from colinin/3.0

Increase event subscriptions for tenants
pull/81/head
cKey 6 years ago
committed by GitHub
parent
commit
0e4f69b40e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/TenantCreateEventHandler.cs
  2. 26
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/TenantDeleteEventHandler.cs
  3. 50
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/TenantUpdateEventHandler.cs
  4. 40
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/TenantCreateEventHandler.cs
  5. 26
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/TenantDeleteEventHandler.cs
  6. 40
      aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/TenantUpdateEventHandler.cs

50
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/TenantCreateEventHandler.cs

@ -0,0 +1,50 @@
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
namespace LINGYUN.Abp.MultiTenancy.DbFinder.EventBus.Distributed
{
public class TenantCreateEventHandler : IDistributedEventHandler<EntityCreatedEto<TenantEto>>, ITransientDependency
{
private readonly IDataFilter _dataFilter;
private readonly ITenantRepository _tenantRepository;
private readonly IDistributedCache<TenantConfigurationCacheItem> _cache;
public TenantCreateEventHandler(
IDataFilter dataFilter,
ITenantRepository tenantRepository,
IDistributedCache<TenantConfigurationCacheItem> cache)
{
_cache = cache;
_dataFilter = dataFilter;
_tenantRepository = tenantRepository;
}
public virtual async Task HandleEventAsync(EntityCreatedEto<TenantEto> eventData)
{
// 禁用租户过滤器
using (_dataFilter.Disable<IMultiTenant>())
{
var tenant = await _tenantRepository.FindAsync(eventData.Entity.Id, true);
if (tenant == null)
{
return;
}
var connectionStrings = new ConnectionStrings();
foreach (var tenantConnectionString in tenant.ConnectionStrings)
{
connectionStrings[tenantConnectionString.Name] = tenantConnectionString.Value;
}
var cacheItem = new TenantConfigurationCacheItem(tenant.Id, tenant.Name, connectionStrings);
var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(eventData.Entity.Id.ToString());
await _cache.SetAsync(cacheKey, cacheItem);
}
}
}
}

26
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/TenantDeleteEventHandler.cs

@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.TenantManagement;
namespace LINGYUN.Abp.MultiTenancy.DbFinder.EventBus.Distributed
{
public class TenantDeleteEventHandler : IDistributedEventHandler<EntityDeletedEto<TenantEto>>, ITransientDependency
{
private readonly IDistributedCache<TenantConfigurationCacheItem> _cache;
public TenantDeleteEventHandler(
IDistributedCache<TenantConfigurationCacheItem> cache)
{
_cache = cache;
}
public virtual async Task HandleEventAsync(EntityDeletedEto<TenantEto> eventData)
{
var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(eventData.Entity.Id.ToString());
await _cache.RemoveAsync(cacheKey);
}
}
}

50
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.DbFinder/LINGYUN/Abp/MultiTenancy/DbFinder/EventBus/Distributed/TenantUpdateEventHandler.cs

@ -0,0 +1,50 @@
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
namespace LINGYUN.Abp.MultiTenancy.DbFinder.EventBus.Distributed
{
public class TenantUpdateEventHandler : IDistributedEventHandler<EntityUpdatedEto<TenantEto>>, ITransientDependency
{
private readonly IDataFilter _dataFilter;
private readonly ITenantRepository _tenantRepository;
private readonly IDistributedCache<TenantConfigurationCacheItem> _cache;
public TenantUpdateEventHandler(
IDataFilter dataFilter,
ITenantRepository tenantRepository,
IDistributedCache<TenantConfigurationCacheItem> cache)
{
_cache = cache;
_dataFilter = dataFilter;
_tenantRepository = tenantRepository;
}
public virtual async Task HandleEventAsync(EntityUpdatedEto<TenantEto> eventData)
{
// 禁用租户过滤器
using (_dataFilter.Disable<IMultiTenant>())
{
var tenant = await _tenantRepository.FindAsync(eventData.Entity.Id, true);
if (tenant == null)
{
return;
}
var connectionStrings = new ConnectionStrings();
foreach (var tenantConnectionString in tenant.ConnectionStrings)
{
connectionStrings[tenantConnectionString.Name] = tenantConnectionString.Value;
}
var cacheItem = new TenantConfigurationCacheItem(tenant.Id, tenant.Name, connectionStrings);
var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(eventData.Entity.Id.ToString());
await _cache.SetAsync(cacheKey, cacheItem);
}
}
}
}

40
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/TenantCreateEventHandler.cs

@ -0,0 +1,40 @@
using LINGYUN.Abp.TenantManagement;
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.TenantManagement;
namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
{
public class TenantCreateEventHandler : IDistributedEventHandler<EntityCreatedEto<TenantEto>>, ITransientDependency
{
private readonly ITenantAppService _tenantAppService;
private readonly IDistributedCache<TenantConfigurationCacheItem> _cache;
public TenantCreateEventHandler(
ITenantAppService tenantAppService,
IDistributedCache<TenantConfigurationCacheItem> cache)
{
_cache = cache;
_tenantAppService = tenantAppService;
}
public virtual async Task HandleEventAsync(EntityCreatedEto<TenantEto> eventData)
{
var tenantDto = await _tenantAppService.GetAsync(eventData.Entity.Id);
var tenantConnectionStringsDto = await _tenantAppService.GetConnectionStringAsync(eventData.Entity.Id);
var connectionStrings = new ConnectionStrings();
foreach (var tenantConnectionString in tenantConnectionStringsDto.Items)
{
connectionStrings[tenantConnectionString.Name] = tenantConnectionString.Value;
}
var cacheItem = new TenantConfigurationCacheItem(tenantDto.Id, tenantDto.Name, connectionStrings);
var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(eventData.Entity.Id.ToString());
await _cache.SetAsync(cacheKey, cacheItem);
}
}
}

26
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/TenantDeleteEventHandler.cs

@ -0,0 +1,26 @@
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.TenantManagement;
namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
{
public class TenantDeleteEventHandler : IDistributedEventHandler<EntityDeletedEto<TenantEto>>, ITransientDependency
{
private readonly IDistributedCache<TenantConfigurationCacheItem> _cache;
public TenantDeleteEventHandler(
IDistributedCache<TenantConfigurationCacheItem> cache)
{
_cache = cache;
}
public virtual async Task HandleEventAsync(EntityDeletedEto<TenantEto> eventData)
{
var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(eventData.Entity.Id.ToString());
await _cache.RemoveAsync(cacheKey);
}
}
}

40
aspnet-core/modules/tenants/LINGYUN.Abp.MultiTenancy.RemoteService/LINGYUN/Abp/MultiTenancy/RemoteService/EventBus/Distributed/TenantUpdateEventHandler.cs

@ -0,0 +1,40 @@
using LINGYUN.Abp.TenantManagement;
using System.Threading.Tasks;
using Volo.Abp.Caching;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities.Events.Distributed;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.TenantManagement;
namespace LINGYUN.Abp.MultiTenancy.RemoteService.EventBus.Distributed
{
public class TenantUpdateEventHandler : IDistributedEventHandler<EntityUpdatedEto<TenantEto>>, ITransientDependency
{
private readonly ITenantAppService _tenantAppService;
private readonly IDistributedCache<TenantConfigurationCacheItem> _cache;
public TenantUpdateEventHandler(
ITenantAppService tenantAppService,
IDistributedCache<TenantConfigurationCacheItem> cache)
{
_cache = cache;
_tenantAppService = tenantAppService;
}
public virtual async Task HandleEventAsync(EntityUpdatedEto<TenantEto> eventData)
{
var tenantDto = await _tenantAppService.GetAsync(eventData.Entity.Id);
var tenantConnectionStringsDto = await _tenantAppService.GetConnectionStringAsync(eventData.Entity.Id);
var connectionStrings = new ConnectionStrings();
foreach (var tenantConnectionString in tenantConnectionStringsDto.Items)
{
connectionStrings[tenantConnectionString.Name] = tenantConnectionString.Value;
}
var cacheItem = new TenantConfigurationCacheItem(tenantDto.Id, tenantDto.Name, connectionStrings);
var cacheKey = TenantConfigurationCacheItem.CalculateCacheKey(eventData.Entity.Id.ToString());
await _cache.SetAsync(cacheKey, cacheItem);
}
}
}
Loading…
Cancel
Save