You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Publishing any event (either manually or committing from an aggregate) fires all event handlers, even those that are not related to the publishing events.
The reproduction repo contains 3 event handlers in different modules and 2 publishing events. Each event fires all existing handlers.
If you go to a.module.ts, you will see the code publishing the events.
@Module({})exportclassAModuleimplementsOnApplicationBootstrap{constructor(privatereadonly_eventPublisher: EventPublisher,privatereadonly_eventBus: EventBus,){}onApplicationBootstrap(){setTimeout(()=>{// ------- v11 ------- //// CASE 1 (commiting from the aggregate root)constuser=newUser(1);user.delete();user.commit();// CASE 2 (publishing manually)// const UserModel = this._eventPublisher.mergeClassContext(User);// const user = new UserModel(1);// this._eventBus.publish(new UserCreatedEvent(user.id));// this._eventBus.publish(new UserDeletedEvent(user.id));// ------- v10 ------- //// CASE 1 (commiting from the aggregate root)// const UserModel = this._eventPublisher.mergeClassContext(User);// const user = new UserModel(1);// user.delete();// user.commit();// CASE 2 (publishing manually)// const UserModel = this._eventPublisher.mergeClassContext(User);// const user = new UserModel(1);// this._eventBus.publish(new UserCreatedEvent(user.id));// this._eventBus.publish(new UserDeletedEvent(user.id));},1000);}}
For v11, both cases lead to the output from the Current behavior section.
Downgrading to v10 npm i @nestjs/cqrs@latest fixes the problem. The output is as in the Expected behavior section for both cases.
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Current behavior
Publishing any event (either manually or committing from an aggregate) fires all event handlers, even those that are not related to the publishing events.
The reproduction repo contains 3 event handlers in different modules and 2 publishing events. Each event fires all existing handlers.
Minimum reproduction code
https://github.com/StimulCross/cqrs-events-problem
Steps to reproduce
Expected behavior
Each event should fire only handlers that listen to this event.
Package version
11.0.0-next.1
NestJS version
10.4.15
Node.js version
22.12.0
In which operating systems have you tested?
Other
If you go to
a.module.ts
, you will see the code publishing the events.For v11, both cases lead to the output from the Current behavior section.
Downgrading to v10
npm i @nestjs/cqrs@latest
fixes the problem. The output is as in the Expected behavior section for both cases.The text was updated successfully, but these errors were encountered: