Context and Dependency Injection (CDI) is the central specification of Java EE. Its role is to manage the beans you define. It is directly linked to the pattern called Inversion of Control (IoC), which provides a way to obtain loose coupling between your classes. The goal is to be flexible on the way so that the current instances are linked together. It also controls the life cycle and the instantiation of instances.
Context and Dependency Injection – what did you do to my beans?
IoC – a pretty simple example
Before exploring the CDI, let's use a very simple example (I would say, a handmade example) to illustrate what a bean container is.
We will use an application that has TimeService, which simply provides...