Geek
Geek

Reputation: 27193

Purpose of CDI technology in Java EE and its relation to UI technologies like JSF and back end technologies like EJB

This question directly follows from another question of mine here. The last paragraph of the answer to that question mentions CDI technology.

Can you explain what is the purpose of that technology. Is there any relation of that technology with JSF and EJB? I have been through this question but I'm not clear on what is the purpose of that technology yet. I specifically want to know where it fits with other Java EE technologies like EJB and JSF.

Upvotes: 4

Views: 388

Answers (2)

Arjan Tijms
Arjan Tijms

Reputation: 38163

Adding to the correct answer of Bozho:

CDI is a superset of JSF's managed beans, and JSF will eventually deprecate their own native managed bean system. In JSF 2.2 steps have already been taken for this.

CDI is not a superset of EJB beans, but they complement each other. CDI does not only provide more advanced DI to EJB beans, but is also capable of giving EJB beans a scope (mostly used for stateful beans). EJB on its turn provides transactional and security services among others , which CDI does not offer. Like JSF managed beans, EJB beans will eventually be merged into the CDI component model. Marina Vatkina (EJB spec lead) among others has strongly hinted at this.

Further reading:

Upvotes: 7

Bozho
Bozho

Reputation: 597056

First, CDI is a dependency-injection standard framework. It defines ways for objects to obtain their dependencies not through instantiation (private FooDao dao = new FooDao()) but via a container which creates and manages instances. You can read more about dependency injection (google/wiki).

The standard defines how that works with both JSF and EJB.

  • your JSF managed beans can be defined via CDI, so that you can inject services into the managed beans, and so that CDI manages the lifecycle of JSF managed beans
  • EJB can also benefit from the advanced dependency injection of CDI (previously they had their own, feature-poor DI).

In short, CDI binds all components in JavaEE in a way spring does with all of its components, but CDI is a standard.

Upvotes: 3

Related Questions