EventSubscriber not Singleton #100
Replies: 3 comments 2 replies
-
The ORM instantiates subscribers only once when the Note that you can as well pass the subscribers via ORM config - there you provide the instances yourself, and you don't use the |
Beta Was this translation helpful? Give feedback.
-
Well, it's possible that when NestJS do the import of the modules, may be that nest calls two times this constructor:
Take a look to the TEST word. Appears two times, once at the top, and one in the middle of the boot. I can avoid that, or I don't know how to do it. Then, I am trying to do using:
without using the @subscriber decorator. But, then, I can not inject the service in the Subscriber, because the subscriber has a service injected, and it wants to I inject when I put it in the init method. What am I doing wrong? Or have I misconception? May be that I can not inject a service in the constructor of a EventSubscriber? |
Beta Was this translation helpful? Give feedback.
-
I missed the @Injectable decorator. Sorry. I finally imported in a provider using @Injectable decorator and I have only one instance with access to the service. Thanks a lot for your help. |
Beta Was this translation helpful? Give feedback.
-
I am using Mikro-orm with NestJS.
I am trying to do a class that EventSubscriber like in documentation:
This is my groups.module.ts, where I import GroupsSubscriber:
And, this is my GroupsSubscriber, that implements EventSubscriber.
The error is that I think that I have two instances from this class, because the output of the console is:
Beta Was this translation helpful? Give feedback.
All reactions