Angular ਦਾ DI hierarchical ਹੈ: injectors ਇੱਕ ਰੁੱਖ ਬਣਾਉਂਦੇ ਹਨ ਜੋ component/module ਰੁੱਖ ਨੂੰ ਪ੍ਰਤੀਬਿੰਬਿਤ ਕਰਦਾ ਹੈ। ਜਦੋਂ ਇੱਕ component ਇੱਕ dependency ਲਈ ਬੇਨਤੀ ਕਰਦਾ ਹੈ, Angular ਉੱਪਰ ਦੀ ਤਰਫ injector ਰੁੱਖ ਵਿੱਚ ਚੱਲਦਾ ਹੈ ਜਦੋਂ ਤੱਕ ਇਹ ਇੱਕ provider ਨੂੰ ਲੱਭ ਨਹੀਂ ਲੈਂਦਾ — ਜੋ ਕਿ ਨਿਯੰਤ੍ਰਿਤ ਕਰਦਾ ਹੈ ਕਿ ਤੁਹਾਨੂੰ ਇੱਕ ਸਾਂਝਾ singleton ਮਿਲਦਾ ਹੈ ਜਾਂ ਪ੍ਰਤੀ component ਇੱਕ ਵੱਖਰੀ instance।
Injector ਦੀ hierarchy
Root injector (app-wide) ← providedIn: 'root' lives here (one singleton)
└─ Module/Route injectors
└─ Component injector ← providers: [...] in @Component
└─ Child component injector
