Comments (9)
Could you please provide a minimal repository which reproduces your issue?
from cqrs.
Hi @kamilmysliwiec ,
I'm currently experiencing the same problem as @JulienKyu. What he meant by his issue is that when two modules have an event handler with the same name, the DI token for both is the same. Therefore only the one registered first will be called, but twice.
I suppose this is something more people are experiencing because it is common to name event handlers by the events they are handling.
Here is a reproduction: https://stackblitz.com/edit/nest-duplicate-event-handlers-reproduction
Although I'm not that deep into the NestJS DI system, I guess it should be possible to scope the event handlers in the ExplorerService to their module.
For everyone else stumbling across this: I'm currently using the same workaround as per the original issue, just prefixing all event handlers with the module name.
from cqrs.
is it fixed, because I am having the same issue?
from cqrs.
Could you please provide a minimal repository which reproduces your issue?
Yes I can, I wait just weekend to do this. Thanks
from cqrs.
To fix temporary this issue I use a custom class named "Projection" with @EventsHandler(...) and this method.
public getEventHandler<E extends IEvent>(event: E): IEventHandler<E> {
const eventHandlerName = event.type + 'Handler';
try {
return this.moduleRef.get(eventHandlerName);
} catch (e) {
this.logger.error(eventHandlerName + ' not implemented');
}
}
I have also register all EventHandler named by the event name followed EventHandler suffix.
With this strategy, I can use each event handler as same name for same event splitted by module.
Dont forget to add type property to all events like this:
....
public type: string;
public constructor() {
this.type = this.constructor.name;
}
....
from cqrs.
Could you please provide a minimal repository which reproduces your issue?
Here is a reproduction: https://github.com/FERNman/nest-duplicate-event-handler
Could you please re open this issue ? or you want I create another issue ?
Thanks a lot
from cqrs.
Hi,
I dont think it's fixed,
examples of simple interest to illustrate the motivation:
Domain (Module)
-Pricing
--OrderCreatedEventHandler
---Update some price
-ProductCatalog
--OrderCreatedEventHandler
---Update inventory
For now, I have not found better method than this to make this example work, with official documentation code sample, OrderCreatedEvent has handle 2 times by first handler named OrderCreatedEventHandler in the module Domain.
@kamilmysliwiec please help us
Thanks a lot
from cqrs.
Any updates with it? I have the same issue. Version of CQRS package - 8.0.0
from cqrs.
I just ran into (I think) the same problem with this. I have two different queries (classes that are the argument for two different @QueryHandler
s) in two different modules, but the incorrect query handler was being used for the query I was calling via the query bus. I double checked that all my imports were correct; that is, the query/handler from the incorrect module was not being imported, but rather the one local to the module. Changing the name of one of the query classes fixed the issue. It does seem like a bug to me.
from cqrs.
Related Issues (20)
- TypeError: You provided 'undefined' where a stream was expected HOT 2
- Middleware chain for command and querybud HOT 2
- Saga events - request context HOT 1
- documentation request HOT 1
- problems constructing instance with Mikro ORM HOT 1
- Feat: Register Commands, Queries & Events programatically HOT 1
- Multiple execution of events based on how many times module is imported HOT 1
- Adjust EventsHandler typing to accept the type of class extending IEvent
- Double events when using microservice HOT 2
- Sagas stop working in case of exceptions HOT 2
- Command handler becomes unresponsive HOT 4
- Event Handler fails to Trigger After Error Occurs HOT 1
- Use a decorator to automatically merge event publisher into AggregateRoot HOT 1
- Http Exceptions thrown in certain situations cause an app crash. HOT 1
- App crashes if event handler triggers a command that throws HOT 1
- CommandHandleException with Command Name not command uuid HOT 2
- Commit method throws an error when trying to publish domain events HOT 1
- Patch update reflect-metadata HOT 1
- Request scope or an alternative for multitenancy, using CQRS module
- Cannot read properties of undefined (reading 'id') - possible breaking change for 8.0.1 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cqrs.