Dependency Injection


Dependency Injection simple means is " injecting the dependency between two object as per as our need/requirement in our application, DI help to reducing the dependency between objects and more beneficiary to unit testing of every objects independently.

When we writing a complex Java application, application classes should be as independent as possible of other Java classes to increase the possibility to reuse these classes and to test them independently of other classes while doing unit testing easily.

In Spring framework, Dependency Injection (DI) design pattern is used to define the object dependencies between each other.

Advantages of Dependency Injection

  • Loosely coupl / Indipendent architecture.
  • Separation of responsibility
  • Configuration and code is separate.
  • Using configuration, a different implementation can be supplied without changing the dependent code.
  • Testing can be performed using mock objects.
  •  Dependency Injection Types

Dependency injection three type : -

  1. Constructor Injection
  2. Setter Injection
  3. Interface-based Injection

Related Articles

post a comment