I need to share a dynamic module. In the documentation I've found that we can share services in the global scope.
Yes, this is a solution. However, I would like to find out if it is possible on the module level. That is why I am interested in what happens when the dynamic module is called few times. From practice, I see that it creates different instances of modules in NestJS.
The module behaviour is different as it is in Angular however the NestJS likes to mention Angular similarity.
The property module takes me away. Now I understand that it is used only to control the module behavior. However, I do not see any
explanation in the documentation. I saw similar questions. But I've not found details that I am interested in.
Regards.
#Share dynamic module in NestJS - what happens when the dynamic module is registered few times?
6 messages · Page 1 of 1 (latest)
I've reported the issue first on StackOverflow - https://stackoverflow.com/questions/77133998/share-dynamic-module-in-nestjs-what-happens-when-the-dynamic-module-is-registe
Does all modules global? That is why they behave like singletons, do not they?
NestJS likes to mention Angular similarity.
Similarity, not parity. They are similar not the same. Differences in behavior are expected
From practice, I see that it creates different instances of modules in NestJS.
This is correct. By convention we use names likeforRootwhen we expect to make something once and re-use it from the root module andregisterwhen we expect to have to register a module multiple times, but this is onyl community convention and not a hard rule at all. When you callDynamicModule.forRoot/register/Async()you will create a dynamic module in thecurrent module's context
If you want to share a dynamic module, I would suggest creating a wrapper around the dynamic module, so you have the wrapper call to the .forRoot()/register()/whaterver() and export the dynamic module by name (add exports: [DynamicModule]. This will allow you to import the wrapper and have one instance of the DynamicModule without having to make it a global instance
If you'd like, I'll add this answer to the StackOverflow question as well
Thank you. Your answer is good. I would appreciate your answer on StackOverflow.