Resolved #1080: Ignore entities on EntityToEtoMapper for those don't implement IEntity.

pull/1089/head
Halil ibrahim Kalkan 6 years ago
parent fc5ab383ee
commit 6ba0ad6618

@ -5,6 +5,8 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
[Serializable] [Serializable]
public class EntityEto : EtoBase public class EntityEto : EtoBase
{ {
public string EntityType { get; set; }
public string KeysAsString { get; set; } public string KeysAsString { get; set; }
public EntityEto() public EntityEto()
@ -12,8 +14,9 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
} }
public EntityEto(string keysAsString) public EntityEto(string entityType, string keysAsString)
{ {
EntityType = entityType;
KeysAsString = keysAsString; KeysAsString = keysAsString;
} }
} }

@ -1,6 +1,5 @@
using System; using Microsoft.Extensions.Options;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy; using Volo.Abp.DynamicProxy;
using Volo.Abp.EventBus.Distributed; using Volo.Abp.EventBus.Distributed;
@ -28,7 +27,7 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
var entity = entityObj as IEntity; var entity = entityObj as IEntity;
if (entity == null) if (entity == null)
{ {
throw new ArgumentException($"{nameof(entityObj)} should be an entity and implement the '{typeof(IEntity).AssemblyQualifiedName}' interface!"); return null;
} }
var entityType = ProxyHelper.UnProxy(entity).GetType(); var entityType = ProxyHelper.UnProxy(entity).GetType();
@ -36,7 +35,7 @@ namespace Volo.Abp.Domain.Entities.Events.Distributed
if (etoType == null) if (etoType == null)
{ {
var keys = entity.GetKeys().JoinAsString(","); var keys = entity.GetKeys().JoinAsString(",");
return new EntityEto(keys); return new EntityEto(entityType.FullName, keys);
} }
//TODO: Also add KeysAsString property to resulting json for compatibility with the EntityEto! //TODO: Also add KeysAsString property to resulting json for compatibility with the EntityEto!

@ -1,7 +1,10 @@
namespace Volo.Abp.Domain.Entities.Events.Distributed using JetBrains.Annotations;
namespace Volo.Abp.Domain.Entities.Events.Distributed
{ {
public interface IEntityToEtoMapper public interface IEntityToEtoMapper
{ {
[CanBeNull]
object Map(object entityObj); object Map(object entityObj);
} }
} }

@ -48,35 +48,83 @@ namespace Volo.Abp.Domain.Entities.Events
public virtual async Task TriggerEntityCreatingEventAsync(object entity) public virtual async Task TriggerEntityCreatingEventAsync(object entity)
{ {
await TriggerEventWithEntity(LocalEventBus, typeof(EntityCreatingEventData<>), entity, true); await TriggerEventWithEntity(
LocalEventBus,
typeof(EntityCreatingEventData<>),
entity,
true
);
} }
public virtual async Task TriggerEntityCreatedEventOnUowCompletedAsync(object entity) public virtual async Task TriggerEntityCreatedEventOnUowCompletedAsync(object entity)
{ {
await TriggerEventWithEntity(LocalEventBus, typeof(EntityCreatedEventData<>), entity, false); await TriggerEventWithEntity(
await TriggerEventWithEntity(DistributedEventBus, typeof(EntityCreatedEto<>), EntityToEtoMapper.Map(entity), false); LocalEventBus,
typeof(EntityCreatedEventData<>),
entity,
false
);
await TriggerEventWithEntity(
DistributedEventBus,
typeof(EntityCreatedEto<>),
EntityToEtoMapper.Map(entity),
false
);
} }
public virtual async Task TriggerEntityUpdatingEventAsync(object entity) public virtual async Task TriggerEntityUpdatingEventAsync(object entity)
{ {
await TriggerEventWithEntity(LocalEventBus, typeof(EntityUpdatingEventData<>), entity, true); await TriggerEventWithEntity(
LocalEventBus,
typeof(EntityUpdatingEventData<>),
entity,
true
);
} }
public virtual async Task TriggerEntityUpdatedEventOnUowCompletedAsync(object entity) public virtual async Task TriggerEntityUpdatedEventOnUowCompletedAsync(object entity)
{ {
await TriggerEventWithEntity(LocalEventBus, typeof(EntityUpdatedEventData<>), entity, false); await TriggerEventWithEntity(
await TriggerEventWithEntity(DistributedEventBus, typeof(EntityUpdatedEto<>), EntityToEtoMapper.Map(entity), false); LocalEventBus,
typeof(EntityUpdatedEventData<>),
entity,
false
);
await TriggerEventWithEntity(
DistributedEventBus,
typeof(EntityUpdatedEto<>),
EntityToEtoMapper.Map(entity),
false
);
} }
public virtual async Task TriggerEntityDeletingEventAsync(object entity) public virtual async Task TriggerEntityDeletingEventAsync(object entity)
{ {
await TriggerEventWithEntity(LocalEventBus, typeof(EntityDeletingEventData<>), entity, true); await TriggerEventWithEntity(
LocalEventBus,
typeof(EntityDeletingEventData<>),
entity,
true
);
} }
public virtual async Task TriggerEntityDeletedEventOnUowCompletedAsync(object entity) public virtual async Task TriggerEntityDeletedEventOnUowCompletedAsync(object entity)
{ {
await TriggerEventWithEntity(LocalEventBus, typeof(EntityDeletedEventData<>), entity, false); await TriggerEventWithEntity(
await TriggerEventWithEntity(DistributedEventBus, typeof(EntityDeletedEto<>), EntityToEtoMapper.Map(entity), false); LocalEventBus,
typeof(EntityDeletedEventData<>),
entity,
false
);
await TriggerEventWithEntity(
DistributedEventBus,
typeof(EntityDeletedEto<>),
EntityToEtoMapper.Map(entity),
false
);
} }
protected virtual async Task TriggerEventsInternalAsync(EntityChangeReport changeReport) protected virtual async Task TriggerEventsInternalAsync(EntityChangeReport changeReport)

Loading…
Cancel
Save