Providing Dependencies Across the Application

Learn how the Angular dependency injection mechanism works and about the phases of dependency check.

We'll cover the following

In this lesson, we’ll learn about the internals of the DI mechanism and how the root injector works. The Angular framework offers an actual injector that can introspect the tokens used to annotate the parameters in the constructor of an Angular artifact.

It returns a singleton instance of the type represented by each dependency so that we can use it straight away in the implementation of our class. The injector maintains a list of all dependencies that an Angular application needs. When a component or other artifact wants to use a dependency, the injector first checks to see if it has already created an instance of this dependency. If not, it creates a new one, returns it to the component, and keeps a copy for further use. The next time the same dependency is requested, it returns the copy previously created. But how does the injector know which dependencies an Angular application needs?

Get hands-on with 1200+ tech skills courses.