Providing dependencies across the application
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?
When we create an Angular service, we use the providedIn
property of the @Injectable
decorator to...