Overview of CDI
The 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 typesafe way, including the ability to choose at deployment time which implementation of a particular interface to inject
In addition, CDI provides the following services:
Integration with the Expression Language (EL), which allows any component to be used directly within a JavaServer Faces page or a JavaServer Pages page
The ability to decorate injected components
The ability to associate interceptors with components using typesafe interceptor bindings
An event-notification model
A web conversation scope in addition to the three standard scopes (request, session, and application) defined by the Java Servlet specification
A complete Service Provider Interface (SPI) that allows third-party frameworks to integrate cleanly in the Java EE 6 environment
A major theme of CDI is loose coupling. CDI does the following:
Decouples the server and the client by means of well-defined types and qualifiers, so that the server implementation may vary
Decouples the lifecycles of collaborating components by doing the following:
Making components contextual, with automatic lifecycle management
Allowing stateful components to interact like services, purely by message passing
Completely decouples message producers from consumers, by means of events
Decouples orthogonal concerns by means of Java EE interceptors
Along with loose coupling, CDI provides strong typing by
Eliminating lookup using string-based names for wiring and correlations, so that the compiler will detect typing errors
Allowing the use of declarative Java annotations to specify everything, largely eliminating the need for XML deployment descriptors, and making it easy to provide tools that introspect the code and understand the dependency structure at development time