Dependency injection

  1. Circumventing the DI system
  2. Sharing services
  3. Providers
  4. DI tricks

In Angular one passes dependencies to a class through its constructor: this clearly defines and tells us what the dependencies of a class are and makes testing really easy.

Since those dependencies may need their own parameters, may have already been instanciated or just need to be mocked, we need a DI system to help us with these tasks.

❗ Place global dependencies in @NgModule - they are going to be instanciated only once.

💡 During testing one can easily inject mock dependencies instead of real ones.