Base solution for your next web application
Open Closed

DomainEvents in AggregateRoot not raised #4538


User avatar
0
ivanosw1 created

Hi, I'm using DDD and in my class that inherits AggregateRoot I use DomaniEvents:

DomainEvents.Add(new CambioCredenzialiEventData(){Email = email});

and the relative handler:

public class CambioCredenzialiEventHandler : IEventHandler<CambioCredenzialiEventData>, ITransientDependency
    {
        public void HandleEvent(CambioCredenzialiEventData eventData){
          ...........
           }
}

In Module Initizialize assembly is registered with

IocManager.RegisterAssemblyByConvention(typeof(MyDomainModule).Assembly);

When the ApplicationService ends his work and repository save the data, nothing happens and the EventHandler is not called. But if I use the EventBus in the ApplicationService, the handler is called.

EventBus.Trigger(new CambioCredenzialiEventData() { Email = input.Email });

Note that if I check MyClass.DomainEvents.Count the result is 1 as expected; What I'm missing to work with DomainEvents ?

Thank you


1 Answer(s)
  • User Avatar
    0
    ivanosw1 created

    I reply to myself.

    After looking to Abp.EntityFrameworkCore.Test and BlogUrlChangeEventData I realised that Aggregate's DomainEvents are raised only if the Aggregate itself is updated by a repository.

    So, as my Domains Entities are unaware of persistence, I have to use EventBus directly.