'NestJs: dynamic module IoC scope

  • How does the framework manage the lifetime of DynamicModules?

The NestJs documentation on Modules states that:

In Nest, modules are singletons by default, and thus you can share the same instance of any provider between multiple modules effortlessly.

  • How can you share multiple dynamic module instances between modules?

The NestJs documentation on DynamicModules states that:

In fact, what our register() method will return is a DynamicModule. A dynamic module is nothing more than a module created at run-time, with the same exact properties as a static module, plus one additional property called module.

  • How can you manage/change the scope of DynamicModules? For example, changing them from behaving transitively to as a singleton. Defining their injection token, retrieving them on demand, etc.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source