Skip to content

What is the right way of adding same discriminators on multiple modules? #147

Closed Answered by GrapeoffJS
ilterugur asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  1. Kindagoose finds all .forFeature calls.
  2. Then it gets the schema that passed in .forFeature arguments.
  3. Looks if it already registered in application.

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:

  1. Kindagoose uses ONLY ONE instance of Typegoose Model, even if you use .forFeature for t…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by GrapeoffJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants