GithubHelp home page GithubHelp logo

Comments (9)

kamilmysliwiec avatar kamilmysliwiec commented on April 26, 2024 2

Could you please provide a minimal repository which reproduces your issue?

from cqrs.

FERNman avatar FERNman commented on April 26, 2024 1

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.

imxm avatar imxm commented on April 26, 2024 1

is it fixed, because I am having the same issue?

from cqrs.

JulienKyu avatar JulienKyu commented on April 26, 2024

Could you please provide a minimal repository which reproduces your issue?

Yes I can, I wait just weekend to do this. Thanks

from cqrs.

JulienKyu avatar JulienKyu commented on April 26, 2024

@FERNman

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.

JulienKyu avatar JulienKyu commented on April 26, 2024

@kamilmysliwiec

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.

JulienKyu avatar JulienKyu commented on April 26, 2024

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.

kobyzskyi avatar kobyzskyi commented on April 26, 2024

Any updates with it? I have the same issue. Version of CQRS package - 8.0.0

from cqrs.

IRCraziestTaxi avatar IRCraziestTaxi commented on April 26, 2024

I just ran into (I think) the same problem with this. I have two different queries (classes that are the argument for two different @QueryHandlers) 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.