What is the right way of adding same discriminators on multiple modules? #147
-
I'm adding discriminators to modules like this. I get this error when I try to add discriminators also on another module:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello! Thanks to perfect GitHub notifications, I did not see your message, I am sorry. All TypeGoose models have only one instance in Nest application. Kindagoose register them in this way:
If Kindagoose finds the provider with the same token, it returns it to the module providers, if not, it creates a new instance of model (see model-factory.ts and discriminator-factory.ts). Since discriminators are models too, the same rules handle them. Let's sum up:
So, you don't need to add discriminators twice in every module. The application will start only when all the dependencies are resolved, then, if you have registered a discriminator in one part of the application, it will be accessible from all the other parts after the app is started. Maybe the logic I just described is counterintuitively, so I think it makes sense to register all the discriminators in Hope it was helpful! |
Beta Was this translation helpful? Give feedback.
Hello! Thanks to perfect GitHub notifications, I did not see your message, I am sorry.
All TypeGoose models have only one instance in Nest application. Kindagoose register them in this way:
.forFeature
calls..forFeature
arguments.If Kindagoose finds the provider with the same token, it returns it to the module providers, if not, it creates a new instance of model (see model-factory.ts and discriminator-factory.ts).
Since discriminators are models too, the same rules handle them.
Let's sum up:
.forFeature
for t…