Introduce the IEventDataMayHaveTenantId interface.

pull/4801/head
Halil İbrahim Kalkan 5 years ago
parent cce16101ad
commit beadedc0c6

@ -1,11 +1,12 @@
using System;
using Volo.Abp.EventBus;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Domain.Entities.Events.Distributed
{
[Serializable]
[GenericEventName(Postfix = ".Created")]
public class EntityCreatedEto<TEntityEto>
public class EntityCreatedEto<TEntityEto> : IEventDataMayHaveTenantId
{
public TEntityEto Entity { get; set; }
@ -13,5 +14,17 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
{
Entity = entity;
}
public virtual bool IsMultiTenant(out Guid? tenantId)
{
if (Entity is IMultiTenant multiTenantEntity)
{
tenantId = multiTenantEntity.TenantId;
return true;
}
tenantId = null;
return false;
}
}
}

@ -1,11 +1,12 @@
using System;
using Volo.Abp.EventBus;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Domain.Entities.Events.Distributed
{
[Serializable]
[GenericEventName(Postfix = ".Deleted")]
public class EntityDeletedEto<TEntityEto>
public class EntityDeletedEto<TEntityEto> : IEventDataMayHaveTenantId
{
public TEntityEto Entity { get; set; }
@ -13,5 +14,17 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
{
Entity = entity;
}
public virtual bool IsMultiTenant(out Guid? tenantId)
{
if (Entity is IMultiTenant multiTenantEntity)
{
tenantId = multiTenantEntity.TenantId;
return true;
}
tenantId = null;
return false;
}
}
}
}

@ -1,11 +1,12 @@
using System;
using Volo.Abp.EventBus;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Domain.Entities.Events.Distributed
{
[Serializable]
[GenericEventName(Postfix = ".Updated")]
public class EntityUpdatedEto<TEntityEto>
public class EntityUpdatedEto<TEntityEto> : IEventDataMayHaveTenantId
{
public TEntityEto Entity { get; set; }
@ -13,5 +14,17 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
{
Entity = entity;
}
public virtual bool IsMultiTenant(out Guid? tenantId)
{
if (Entity is IMultiTenant multiTenantEntity)
{
tenantId = multiTenantEntity.TenantId;
return true;
}
tenantId = null;
return false;
}
}
}
}

@ -1,5 +1,6 @@
using System;
using Volo.Abp.EventBus;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Domain.Entities.Events
{
@ -8,7 +9,7 @@ namespace Volo.Abp.Domain.Entities.Events
/// </summary>
/// <typeparam name="TEntity">Entity type</typeparam>
[Serializable]
public class EntityEventData<TEntity> : IEventDataWithInheritableGenericArgument
public class EntityEventData<TEntity> : IEventDataWithInheritableGenericArgument, IEventDataMayHaveTenantId
{
/// <summary>
/// Related entity with this event.
@ -28,5 +29,17 @@ namespace Volo.Abp.Domain.Entities.Events
{
return new object[] { Entity };
}
public virtual bool IsMultiTenant(out Guid? tenantId)
{
if (Entity is IMultiTenant multiTenantEntity)
{
tenantId = multiTenantEntity.TenantId;
return true;
}
tenantId = null;
return false;
}
}
}
}

@ -0,0 +1,28 @@
using System;
namespace Volo.Abp.EventBus
{
/// <summary>
/// An event data object (or event transfer object) can implement this interface
/// to indicate that this event may be related to a tenant.
///
/// If an event data class is always related to a tenant, then directly implement the
/// <see cref="IsMultiTenant"/> interface instead of this one.
///
/// This interface is typically implemented by generic event handlers where the generic
/// parameter may implement <see cref="IsMultiTenant"/> or not.
/// </summary>
public interface IEventDataMayHaveTenantId
{
/// <summary>
/// Returns true if this event data has a Tenant Id information.
/// If so, it should set the <see cref="tenantId"/> our parameter.
/// Otherwise, the <see cref="tenantId"/> our parameter value should not be informative
/// (it will be null as expected, but doesn't indicate a tenant with null tenant id).
/// </summary>
/// <param name="tenantId">
/// The tenant id that is set if this method returns true.
/// </param>
bool IsMultiTenant(out Guid? tenantId);
}
}
Loading…
Cancel
Save