DI is a key paradigm of nestjs. Here's some experience I got after nestjs experiment.
- Provider are scoped within a module. If you want a provider available everywhere, you need to attach it to a global module using
- If a non-global provider is imported into multiple modules, it's initialized multiple times. Global module's providers are initialized only once.
- Providers can use injected providers of their own using
- Providers by default are useClass. Other options are
- Providers can be async if
useFactoryreturns a promise. Then application's startup will be delayed till async tasks are finished.