mirror of https://github.com/abpframework/abp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp.DependencyInjection;
|
|
using Volo.Abp.Domain.Entities.Events.Distributed;
|
|
using Volo.Abp.MultiTenancy;
|
|
|
|
namespace Volo.Abp.EventBus.Distributed;
|
|
|
|
public class MySimpleDistributedSingleInstanceEventHandler : IDistributedEventHandler<MySimpleEventData>, IDistributedEventHandler<EntityCreatedEto<MySimpleEventData>>, IDistributedEventHandler<MySimpleEto>, ITransientDependency
|
|
{
|
|
private readonly ICurrentTenant _currentTenant;
|
|
|
|
public MySimpleDistributedSingleInstanceEventHandler(ICurrentTenant currentTenant)
|
|
{
|
|
_currentTenant = currentTenant;
|
|
}
|
|
|
|
public static Guid? TenantId { get; set; }
|
|
|
|
public Task HandleEventAsync(MySimpleEventData eventData)
|
|
{
|
|
TenantId = _currentTenant.Id;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task HandleEventAsync(EntityCreatedEto<MySimpleEventData> eventData)
|
|
{
|
|
TenantId = _currentTenant.Id;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task HandleEventAsync(MySimpleEto eventData)
|
|
{
|
|
var tenantIdString = eventData.Properties.GetOrDefault("TenantId").ToString();
|
|
TenantId = tenantIdString != null ? new Guid(tenantIdString) : _currentTenant.Id;
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|