From 30bd5caf2eb7c82866efe745421ab40e65df94eb Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:22:02 +0800 Subject: [PATCH 1/4] Remove EntityCreatingEventData, EntityUpdatingEventData, EntityDeletingEventData and EntityChangingEventData --- .../Events/EntityChangeEventHelper.cs | 227 ------------------ .../Events/EntityChangingEventData.cs | 23 -- .../Events/EntityCreatingEventData.cs | 22 -- .../Events/EntityDeletingEventData.cs | 22 -- .../Events/EntityUpdatingEventData.cs | 22 -- .../Testing/EntityChangeEvents_Tests.cs | 19 +- 6 files changed, 1 insertion(+), 334 deletions(-) delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs deleted file mode 100644 index 8f9be2318f..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs +++ /dev/null @@ -1,227 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Microsoft.Extensions.Options; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Domain.Entities.Events.Distributed; -using Volo.Abp.DynamicProxy; -using Volo.Abp.EventBus; -using Volo.Abp.EventBus.Distributed; -using Volo.Abp.EventBus.Local; -using Volo.Abp.Uow; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// Used to trigger entity change events. -/// -public class EntityChangeEventHelper : IEntityChangeEventHelper, ITransientDependency -{ - private const string UnitOfWorkEventRecordEntityPropName = "_Abp_Entity"; - - public ILogger Logger { get; set; } - public ILocalEventBus LocalEventBus { get; set; } - public IDistributedEventBus DistributedEventBus { get; set; } - - protected IUnitOfWorkManager UnitOfWorkManager { get; } - protected IEntityToEtoMapper EntityToEtoMapper { get; } - protected AbpDistributedEntityEventOptions DistributedEntityEventOptions { get; } - - public EntityChangeEventHelper( - IUnitOfWorkManager unitOfWorkManager, - IEntityToEtoMapper entityToEtoMapper, - IOptions distributedEntityEventOptions) - { - UnitOfWorkManager = unitOfWorkManager; - EntityToEtoMapper = entityToEtoMapper; - DistributedEntityEventOptions = distributedEntityEventOptions.Value; - - LocalEventBus = NullLocalEventBus.Instance; - DistributedEventBus = NullDistributedEventBus.Instance; - Logger = NullLogger.Instance; - } - - public virtual void PublishEntityCreatingEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, -#pragma warning disable 618 - typeof(EntityCreatingEventData<>), -#pragma warning restore 618 - entity, - entity - ); - } - - public virtual void PublishEntityCreatedEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, - typeof(EntityCreatedEventData<>), - entity, - entity - ); - - if (ShouldPublishDistributedEventForEntity(entity)) - { - var eto = EntityToEtoMapper.Map(entity); - if (eto != null) - { - TriggerEventWithEntity( - DistributedEventBus, - typeof(EntityCreatedEto<>), - eto, - entity - ); - } - } - } - - private bool ShouldPublishDistributedEventForEntity(object entity) - { - return DistributedEntityEventOptions - .AutoEventSelectors - .IsMatch( - ProxyHelper - .UnProxy(entity) - .GetType() - ); - } - - public virtual void PublishEntityUpdatingEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, -#pragma warning disable 618 - typeof(EntityUpdatingEventData<>), -#pragma warning restore 618 - entity, - entity - ); - } - - public virtual void PublishEntityUpdatedEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, - typeof(EntityUpdatedEventData<>), - entity, - entity - ); - - if (ShouldPublishDistributedEventForEntity(entity)) - { - var eto = EntityToEtoMapper.Map(entity); - if (eto != null) - { - TriggerEventWithEntity( - DistributedEventBus, - typeof(EntityUpdatedEto<>), - eto, - entity - ); - } - } - } - - public virtual void PublishEntityDeletingEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, -#pragma warning disable 618 - typeof(EntityDeletingEventData<>), -#pragma warning restore 618 - entity, - entity - ); - } - - public virtual void PublishEntityDeletedEvent(object entity) - { - TriggerEventWithEntity( - LocalEventBus, - typeof(EntityDeletedEventData<>), - entity, - entity - ); - - if (ShouldPublishDistributedEventForEntity(entity)) - { - var eto = EntityToEtoMapper.Map(entity); - if (eto != null) - { - TriggerEventWithEntity( - DistributedEventBus, - typeof(EntityDeletedEto<>), - eto, - entity - ); - } - } - } - - protected virtual void TriggerEventWithEntity( - IEventBus eventPublisher, - Type genericEventType, - object entityOrEto, - object originalEntity) - { - var entityType = ProxyHelper.UnProxy(entityOrEto).GetType(); - var eventType = genericEventType.MakeGenericType(entityType); - var eventData = Activator.CreateInstance(eventType, entityOrEto); - var currentUow = UnitOfWorkManager.Current; - - if (currentUow == null) - { - Logger.LogWarning("UnitOfWorkManager.Current is null! Can not publish the event."); - return; - } - - var eventRecord = new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext()) - { - Properties = - { - { UnitOfWorkEventRecordEntityPropName, originalEntity }, - } - }; - - /* We are trying to eliminate same events for the same entity. - * In this way, for example, we don't trigger update event for an entity multiple times - * even if it is updated multiple times in the current UOW. - */ - - if (eventPublisher == DistributedEventBus) - { - currentUow.AddOrReplaceDistributedEvent( - eventRecord, - otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) - ); - } - else - { - currentUow.AddOrReplaceLocalEvent( - eventRecord, - otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) - ); - } - } - - public bool IsSameEntityEventRecord(UnitOfWorkEventRecord record1, UnitOfWorkEventRecord record2) - { - if (record1.EventType != record2.EventType) - { - return false; - } - - var record1OriginalEntity = record1.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; - var record2OriginalEntity = record2.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; - - if (record1OriginalEntity == null || record2OriginalEntity == null) - { - return false; - } - - return EntityHelper.EntityEquals(record1OriginalEntity, record2OriginalEntity); - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs deleted file mode 100644 index ae24163966..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangingEventData.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// Used to pass data for an event when an entity () is being changed (creating, updating or deleting). -/// See , and classes. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityChangedEventData. Please use EntityChangedEventData instead.")] -public class EntityChangingEventData : EntityEventData -{ - /// - /// Constructor. - /// - /// Changing entity in this event - public EntityChangingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs deleted file mode 100644 index 914c8ca7c7..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityCreatingEventData.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// This type of event is used to notify just before creation of an Entity. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityCreatedEventData. Please use EntityCreatedEventData instead.")] -public class EntityCreatingEventData : EntityChangingEventData -{ - /// - /// Constructor. - /// - /// The entity which is being created - public EntityCreatingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs deleted file mode 100644 index af0d1218f7..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityDeletingEventData.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// This type of event is used to notify just before deletion of an Entity. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityDeletedEventData. Please use EntityDeletedEventData instead.")] -public class EntityDeletingEventData : EntityChangingEventData -{ - /// - /// Constructor. - /// - /// The entity which is being deleted - public EntityDeletingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs deleted file mode 100644 index 703304fefb..0000000000 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityUpdatingEventData.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; - -namespace Volo.Abp.Domain.Entities.Events; - -/// -/// This type of event is used to notify just before update of an Entity. -/// -/// Entity type -[Serializable] -[Obsolete("This event is no longer needed and identical to EntityUpdatedEventData. Please use EntityUpdatedEventData instead.")] -public class EntityUpdatingEventData : EntityChangingEventData -{ - /// - /// Constructor. - /// - /// The entity which is being updated - public EntityUpdatingEventData(TEntity entity) - : base(entity) - { - - } -} diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs index a94c722faf..c6ffa48d37 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs @@ -38,23 +38,6 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase using (var uow = GetRequiredService().Begin()) { -#pragma warning disable 618 - LocalEventBus.Subscribe>(data => -#pragma warning restore 618 - { - creatingEventTriggered.ShouldBeFalse(); - createdEventTriggered.ShouldBeFalse(); - - creatingEventTriggered = true; - - data.Entity.Name.ShouldBe(personName); - - /* Want to change age from 15 to 18 */ - data.Entity.Age.ShouldBe(15); - data.Entity.Age = 18; - return Task.CompletedTask; - }); - LocalEventBus.Subscribe>(data => { creatingEventTriggered.ShouldBeTrue(); @@ -62,7 +45,7 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase createdEventTriggered = true; - data.Entity.Age.ShouldBe(18); + data.Entity.Age.ShouldBe(15); data.Entity.Name.ShouldBe(personName); return Task.CompletedTask; From 300cde89c28e3759e01bf713b3c3647b4843a497 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:27:39 +0800 Subject: [PATCH 2/4] Update EntityChangeEventHelper.cs --- .../Events/EntityChangeEventHelper.cs | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs new file mode 100644 index 0000000000..20556f16ff --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/EntityChangeEventHelper.cs @@ -0,0 +1,191 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Entities.Events.Distributed; +using Volo.Abp.DynamicProxy; +using Volo.Abp.EventBus; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.EventBus.Local; +using Volo.Abp.Uow; + +namespace Volo.Abp.Domain.Entities.Events; + +/// +/// Used to trigger entity change events. +/// +public class EntityChangeEventHelper : IEntityChangeEventHelper, ITransientDependency +{ + private const string UnitOfWorkEventRecordEntityPropName = "_Abp_Entity"; + + public ILogger Logger { get; set; } + public ILocalEventBus LocalEventBus { get; set; } + public IDistributedEventBus DistributedEventBus { get; set; } + + protected IUnitOfWorkManager UnitOfWorkManager { get; } + protected IEntityToEtoMapper EntityToEtoMapper { get; } + protected AbpDistributedEntityEventOptions DistributedEntityEventOptions { get; } + + public EntityChangeEventHelper( + IUnitOfWorkManager unitOfWorkManager, + IEntityToEtoMapper entityToEtoMapper, + IOptions distributedEntityEventOptions) + { + UnitOfWorkManager = unitOfWorkManager; + EntityToEtoMapper = entityToEtoMapper; + DistributedEntityEventOptions = distributedEntityEventOptions.Value; + + LocalEventBus = NullLocalEventBus.Instance; + DistributedEventBus = NullDistributedEventBus.Instance; + Logger = NullLogger.Instance; + } + + public virtual void PublishEntityCreatedEvent(object entity) + { + TriggerEventWithEntity( + LocalEventBus, + typeof(EntityCreatedEventData<>), + entity, + entity + ); + + if (ShouldPublishDistributedEventForEntity(entity)) + { + var eto = EntityToEtoMapper.Map(entity); + if (eto != null) + { + TriggerEventWithEntity( + DistributedEventBus, + typeof(EntityCreatedEto<>), + eto, + entity + ); + } + } + } + + private bool ShouldPublishDistributedEventForEntity(object entity) + { + return DistributedEntityEventOptions + .AutoEventSelectors + .IsMatch( + ProxyHelper + .UnProxy(entity) + .GetType() + ); + } + + public virtual void PublishEntityUpdatedEvent(object entity) + { + TriggerEventWithEntity( + LocalEventBus, + typeof(EntityUpdatedEventData<>), + entity, + entity + ); + + if (ShouldPublishDistributedEventForEntity(entity)) + { + var eto = EntityToEtoMapper.Map(entity); + if (eto != null) + { + TriggerEventWithEntity( + DistributedEventBus, + typeof(EntityUpdatedEto<>), + eto, + entity + ); + } + } + } + + public virtual void PublishEntityDeletedEvent(object entity) + { + TriggerEventWithEntity( + LocalEventBus, + typeof(EntityDeletedEventData<>), + entity, + entity + ); + + if (ShouldPublishDistributedEventForEntity(entity)) + { + var eto = EntityToEtoMapper.Map(entity); + if (eto != null) + { + TriggerEventWithEntity( + DistributedEventBus, + typeof(EntityDeletedEto<>), + eto, + entity + ); + } + } + } + + protected virtual void TriggerEventWithEntity( + IEventBus eventPublisher, + Type genericEventType, + object entityOrEto, + object originalEntity) + { + var entityType = ProxyHelper.UnProxy(entityOrEto).GetType(); + var eventType = genericEventType.MakeGenericType(entityType); + var eventData = Activator.CreateInstance(eventType, entityOrEto); + var currentUow = UnitOfWorkManager.Current; + + if (currentUow == null) + { + Logger.LogWarning("UnitOfWorkManager.Current is null! Can not publish the event."); + return; + } + + var eventRecord = new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext()) + { + Properties = + { + { UnitOfWorkEventRecordEntityPropName, originalEntity }, + } + }; + + /* We are trying to eliminate same events for the same entity. + * In this way, for example, we don't trigger update event for an entity multiple times + * even if it is updated multiple times in the current UOW. + */ + + if (eventPublisher == DistributedEventBus) + { + currentUow.AddOrReplaceDistributedEvent( + eventRecord, + otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) + ); + } + else + { + currentUow.AddOrReplaceLocalEvent( + eventRecord, + otherRecord => IsSameEntityEventRecord(eventRecord, otherRecord) + ); + } + } + + public bool IsSameEntityEventRecord(UnitOfWorkEventRecord record1, UnitOfWorkEventRecord record2) + { + if (record1.EventType != record2.EventType) + { + return false; + } + + var record1OriginalEntity = record1.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; + var record2OriginalEntity = record2.Properties.GetOrDefault(UnitOfWorkEventRecordEntityPropName) as IEntity; + + if (record1OriginalEntity == null || record2OriginalEntity == null) + { + return false; + } + + return EntityHelper.EntityEquals(record1OriginalEntity, record2OriginalEntity); + } +} From f9e903b43b3adf437f9607f5e4350e0dd5639370 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:44:29 +0800 Subject: [PATCH 3/4] Improve --- .../Entities/Events/IEntityChangeEventHelper.cs | 3 --- .../Entities/Events/NullEntityChangeEventHelper.cs | 12 ------------ .../Volo/Abp/EntityFrameworkCore/AbpDbContext.cs | 4 ---- .../Repositories/MemoryDb/MemoryDbRepository.cs | 3 --- .../Domain/Repositories/MongoDB/MongoDbRepository.cs | 3 --- 5 files changed, 25 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs index db580a0682..aa63c7e3c9 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/IEntityChangeEventHelper.cs @@ -5,12 +5,9 @@ namespace Volo.Abp.Domain.Entities.Events; /// public interface IEntityChangeEventHelper { - void PublishEntityCreatingEvent(object entity); void PublishEntityCreatedEvent(object entity); - void PublishEntityUpdatingEvent(object entity); void PublishEntityUpdatedEvent(object entity); - void PublishEntityDeletingEvent(object entity); void PublishEntityDeletedEvent(object entity); } diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs index d428f84d6f..4d849f2f27 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/NullEntityChangeEventHelper.cs @@ -14,26 +14,14 @@ public class NullEntityChangeEventHelper : IEntityChangeEventHelper { } - public void PublishEntityCreatingEvent(object entity) - { - } - public void PublishEntityCreatedEvent(object entity) { } - public void PublishEntityUpdatingEvent(object entity) - { - } - public void PublishEntityUpdatedEvent(object entity) { } - public void PublishEntityDeletingEvent(object entity) - { - } - public void PublishEntityDeletedEvent(object entity) { } diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 3a8a24bf62..fd998510af 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -292,7 +292,6 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, { case EntityState.Added: ApplyAbpConceptsForAddedEntity(entry); - EntityChangeEventHelper.PublishEntityCreatingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityCreatedEvent(entry.Entity); break; case EntityState.Modified: @@ -301,12 +300,10 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, { if (entry.Entity is ISoftDelete && entry.Entity.As().IsDeleted) { - EntityChangeEventHelper.PublishEntityDeletingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityDeletedEvent(entry.Entity); } else { - EntityChangeEventHelper.PublishEntityUpdatingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityUpdatedEvent(entry.Entity); } } @@ -314,7 +311,6 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, break; case EntityState.Deleted: ApplyAbpConceptsForDeletedEntity(entry); - EntityChangeEventHelper.PublishEntityDeletingEvent(entry.Entity); EntityChangeEventHelper.PublishEntityDeletedEvent(entry.Entity); break; } diff --git a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index 2bcfc1bad7..61bb9745e2 100644 --- a/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -159,19 +159,16 @@ public class MemoryDbRepository : RepositoryBase private void TriggerEntityCreateEvents(TEntity entity) { - EntityChangeEventHelper.PublishEntityCreatingEvent(entity); EntityChangeEventHelper.PublishEntityCreatedEvent(entity); } protected virtual void TriggerEntityUpdateEvents(TEntity entity) { - EntityChangeEventHelper.PublishEntityUpdatingEvent(entity); EntityChangeEventHelper.PublishEntityUpdatedEvent(entity); } @@ -616,7 +614,6 @@ public class MongoDbRepository protected virtual void TriggerEntityDeleteEvents(TEntity entity) { - EntityChangeEventHelper.PublishEntityDeletingEvent(entity); EntityChangeEventHelper.PublishEntityDeletedEvent(entity); } From 03e7412e9aece512dd1da0665fe2c15fa0a3ce7a Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 29 Jul 2022 11:46:57 +0800 Subject: [PATCH 4/4] Update EntityChangeEvents_Tests.cs --- .../Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs index c6ffa48d37..12b3fa01c0 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/EntityChangeEvents_Tests.cs @@ -32,7 +32,6 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase { var personName = Guid.NewGuid().ToString("N"); - var creatingEventTriggered = false; var createdEventTriggered = false; var createdEtoTriggered = false; @@ -40,7 +39,6 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase { LocalEventBus.Subscribe>(data => { - creatingEventTriggered.ShouldBeTrue(); createdEventTriggered.ShouldBeFalse(); createdEventTriggered = true; @@ -64,8 +62,7 @@ public abstract class EntityChangeEvents_Tests : TestAppTestBase await uow.CompleteAsync(); } - - creatingEventTriggered.ShouldBeTrue(); + createdEventTriggered.ShouldBeTrue(); createdEtoTriggered.ShouldBeTrue(); }