Skip to content
Angular Essentials
GitHub

Overview

  • DI is wired into the Angular framework and allows classes with Angular decorators, such as Components, Directives, Pipes, and Injectables, to configure dependencies that they need.
  • Two main roles exist in the DI system: dependency consumer and dependency provider.
  • Angular facilitates the interaction between dependency consumers and dependency providers using an abstraction called Injector.
  • An object in the Angular dependency-injection system that can find a named dependency in its cache or create a dependency using a configured provider.
  • When a dependency is requested, the injector checks its registry to see if there is an instance already available there. If not, a new instance is created and stored in the registry.
  • Angular creates an application-wide injector (also known as “root” injector) during the application bootstrap process, as well as any other injectors as needed.
  • In most cases you don’t need to manually create injectors, but you should know that there is a layer that connects providers and consumers.

An injector provides a singleton instance of a dependency, and can inject this same instance in multiple components.