Services

Platform

Domain

Services

Platform

Domain

The IOC Container – Spring Framework

In this article, we’ll discuss the concept of IOC andIOC Container, and then we’ll dive deep into the implementation of IOC container with Spring Framework.

let’s first understand the concept of Inversion of control(IOC). The IOC is a design principle in software engineering. We can easily understand it by Simple Scenario based example described below.

Example: When we are using any framework so the framework is performing most of the tasks for us but there is some particular situation where our custom code needs to be called and perform some custom logic and tasks, The framework is going along with allocating resources and determining when the object or tasks get called so when there is turn for our application specific logic the framework calls in our custom code and our code returns the control back to the framework, this whole flow is known as Inversion Of Control. The image below describes the flow of given example for IOC

let’s now understand theIOC Containerwith Spring framework. The IOC Container is also know as Spring container which is at the core of Spring Framework. The IOC Container is implemented using Dependency Injection design pattern. IOC Container is responsible to instantiate, configure and assemble the objects as well as manages object’s complete life cycle .

The IOC container gets instructions on what objects to instantiate, configure, and assemble by reading the configuration metadata provided. The configuration metadata can be represented either by XML, Java annotations, or Java code where the objects are known as Beans.

The image shown below describes high level view of how Spring works.

The IOC Container uses Business Objects(POJOs) and Configuration metadata to come up with fully configured system.

There are two types of IOC containers.

BeanFactory and ApplicationContext

The ApplicationContext interface is built on top of the BeanFactory interface. It adds more functionality than BeanFactory such as simple integration with Spring’s AOP, application layer specific context (e.g. WebApplicationContext) for web application. ApplicationContext is generally recommended over BeanFactory.

Stay up-to-date with FAIR

Connect with FAIR today and get the latest tips and tricks on improving your CX tools and eCommerce platforms. Once you subscribe you will get access to workshops, webinars, recent projects and so much more.