2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Dependency Injection and Inversion of Control in Spring Framework?

When we entered into the learning of Spring then these are the two terms which we listen first. But the programmers like me still has a doubt on these after completion of the subject too.

Is there any simpler way to learn and understand this properly? Please suggest!
userimage

Find some basic points here,

  • Spring helps in creating loosely coupled application because of Dependency Injection.
  • In spring objects define their associations (dependencies) and do not worry about how to get those dependencies ; now it is the responsibility of Spring to provide the required dependencies for creating objects.
  • Inversion of Control (IOC) and Dependency Injection (DI) are used interchangeably. IOC is achieved through DI. DI is the process of providing the dependencies and IOC is the end result of DI (Note: DI is not the only way to achieve IOC, there are other ways as well).

  • By DI the responsibility of creating objects is shifted from our application code to Spring container hence the phenomenon is called IOC.

  • Dependency Injection can be done by setter injection, constructor injection.

I know these few points will not make you clear. So refer to the below location where you can able to find the simple explanation towards your concerns.



Answer is