Dependency Injection Types

less than 1 minute read

Basically there are three types of dependency injection, Depending on the context we can choose any type which is being supported by that framework. Three types are:

Constructor DI: In the constructor injection, injector supplies service or dependency through the client or dependent constructor.

Property DI: In property injection also known as Setter Injection, injector supplies service or dependency through a public property of the client (dependent).

Method DI: In this type of injection, client (dependent) implements an interface which declares method/s to supply service (dependency) and the injector uses this interface to supply service (dependency) to the client (dependent).

In our video session 0008-3- Types of Dependency Injection we have explained in detail like where to use which type of DI depending on the framework being used. Angular currently supports Constructor DI only. We can implement dependency injection on our own or can use third-party libraries or frameworks. Few of Libraries and Frameworks that implement DI are:

  • Spring (Java)
  • Dagger (Java & Android)
  • Unity (.Net)