Contexts and Dependency Injection 2.0 overview

Liberty provides support for Contexts and Dependency Injection (CDI) in applications by using the Liberty features cdi-2.0, cdi-1.2, and cdi-1.0.

The CDI 2.0 feature provides full support for the CDI 2.0 specification. Full descriptions of the CDI 2.0 functions are provided in the CDI 2.0 specification; see Contexts and Dependency Injection for Java 2.0.

The set of services that are provided by the CDI 2.0 feature includes a well-defined lifecycle for stateful objects that are bound to lifecycle contexts and a typesafe dependency injection mechanism.

Using Contexts and Dependency Injection 2.0 with JavaServer Faces applications

You can use the CDI 2.0 feature with the JavaServer Faces (JSF) 2.3 feature to enable JSF applications to take advantage of the sophisticated context and dependency injection model that is provided in the CDI 2.0 feature. This service is provided through integration with the Unified Expression Language (EL) which enables any contextual object to be used directly within a JSF or JavaServer Pages (JSP) page.

Using Contexts and Dependency Injection 2.0 with Enterprise JavaBeans (EJB)

You can use the CDI 2.0 feature with the Enterprise JavaBeans (EJB) 3.2 feature to enhance the EJB component model with contextual lifecycle management. The services that are provided by the CDI 2.0 feature integrate the Java EE web tier with Java EE enterprise services. In particular, this enables EJB components to be used as JSF managed beans, thus integrating the programming models of EJB and JSF.

Using Contexts and Dependency Injection 2.0 with Servlet 4.0

You can use the CDI 2.0 feature with the Servlet 4.0 feature to enable servlet applications to take full advantage of the services that are provided by the CDI 2.0 feature. Using both features enables contextual managed beans to be injected into servlet applications by using field, method or constructor injection. The CDI 2.0 feature also provides automatic registration of servlet listeners, filters, and interceptors.

Java Interceptors in Contexts and Dependency Injection 2.0 applications

The CDI 2.0 feature extends the Java model for interceptors. The CDI 2.0 feature provides the ability to associate interceptors with beans. The interceptors are bound by using typesafe interceptor bindings. This model can be extended to EJB beans when both the CDI 2.0 and EJB 3.2 features are loaded onto the Liberty server.