IOC (Inversion of control)


Spring Inversion of Control

Inversion of Control is a software engineering approach that shifts control of the object or part of a program into a container or framework. In object-oriented programming, we utilize it most frequently.

Unlike traditional programming, in which our custom code calls to a library, IoC allows a frame to govern the program's flow and make calls to our code. To allow this, frameworks leverage other behavior built-in abstractions. If we wish to add our own behavior, we must expand the frame classes or add our classes.

Instantiate, configure and build the objects using the IoC container. The IoC container receives XML file information and functions accordingly. IoC container's main tasks include:

  • Instantiating application class.
  • Configuring object.
  • Assembling dependencies among the objects.

Two kinds of IoC containers are available, which are as follows:

  • BeanFactory
  • ApplicationContext

Difference between BeanFactory and the context of application

The org.spring framework.beans.fact.beanFactory and org.Springframework.context. The IoC container is the ApplicationContext interface. On top of a BeanFactory interface, the ApplicationContext interface is created. The system includes additional capabilities like straightforward integration with Spring's AOP, message resource handling (for I18N), event propagation, unique context of application layer for web application (i.e., WebApplicationContext). ApplicationContext is preferable to use than BeanFactory.