Since Angular 9
Use @Injectable({ providedIn: 'root' })
With providedIn: '...'
the service will discovered by the Angular compiler. It is then not necessary to add the service to providers anymore.
https://angular.io/guide/providers
Original answer
When you add a service to the providers:
list of a component you get a new instance for every component.
Add it only to bootstrap(AppComponent, [AService])
and the whole application gets the same reference.
In Angulars DI every provided instance is a singleton, but only within the scope of the injector that created the instance.
Angulars DI is hierarchical. For each component a child-injector is created. DI starts with the closest injector to resolve the required type. If there is a provider but no instance yet, one will created. If there is no provider DI iterates to the parent injector until it finds one or until it reaches the root injector. If it reached the root injector and still didn't find a provider it throws.
The providers added to bootstrap()
are the providers for the root injector and therefore applicable for the whole application when not further down the hierarchy another injector has a provider for the same type registered.