Tags

, ,


As Java EE 6 tutorial says:

The two most fundamental services provided by CDI are as follows:

  • Contexts: The ability to bind the lifecycle and interactions of stateful components to well-defined but extensible lifecycle contexts
  • Dependency injection: The ability to inject components into an application in a type-safe way, including the ability to choose at deployment time which implementation of a particular interface to inject

Let’s discuss with an example.

Suppose you are a frequent traveler need to travel from New Heaven to New York thrice a week and your nearest airport is Hartford. Every time you take a cab or drive to airport then take flight and fly to NY., i.e you are a dependent of  transport service.

So, we can say that,in this case the type (Concrete Implementation) of the service depends on the source and destination and putting that concrete implementation in place at runtime (Injection) depending on scenario(i.e. Context) is  Context & Dependency Injection.

JEE 6 uses annotation(Which had been introduced at Java 5) heavily to make developers’ life hassle free from writing lines of XML configuration.Five annotation constructs :

  1. @Inject,
  2. @Qualifier,
  3. @Produces,
  4. @Disposes and
  5. @Named

provide the basic building blocks for getting a thin loosely coupled layered modular structure to the view, hiding the boilerplate code one had to write before JEE 6.

I shall write more on this topic as I shall learn more. 🙂

Advertisements