# NestJS DI ###### tags: `learning` ### What is DI, IoC, IoC container anyway? ### NestJS module revisited  - Root module - Feature module - Global module - Module import tree - Handon Refs: https://docs.nestjs.com/modules ### NestJS provider revisited  - Services, repositories, helpers... - Injectable - DI - Contructor-based - Property-based - What if we don't have access to DI for a particular provider? - In `bootstrap()` method - Injection scopes - Default - Hierarchy - Handon - Class-based vs non-class-based & short-hand - Custom provider with compatible interface (structural typing) - IoC container and DI flow ```plantuml @startuml (*) --> Factory create (NestFactory) --> Create IoC container (NestContainer) --> Scan and register dependencies meta (providers, controllers...) to IoC container (DependenciesScanner) --> Instantiate dependencies (DI) (InstanceLoader & Injector) --> Application initialization (NestApplication) @enduml ``` Refs: https://docs.nestjs.com/providers https://docs.nestjs.com/fundamentals/custom-providers https://github.com/nestjs/nest/blob/master/packages/core/nest-factory.ts ### Common issues #### Circular dependency - Forward ref (provider vs module) - Barrel file #### Cannot resolve dependencies https://docs.nestjs.com/faq/common-errors -
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up