Events are an important part of the JavaBeans model. You have probably used events in Abstract Windowing Toolkit (AWT) and Swing applications by registering a listener on a component. When you click the component (like a button), an event is fired and handled by the registered listener.
Contexts and Dependency Injection (CDI) was introduced with Java Platform, Enterprise Edition (Java EE) 6 as JSR-299. The Contexts part of CDI allows beans to share and participate in the life cycle of another bean, while the Dependency Injection part of CDI allows beans to get a reference to an instance of another bean simply by injecting it. CDI power is the ability to loosely-couple classes by removing the instantiation process and simultaneously enforcing strong-type checking. CDI provides an @Inject annotation to create a reference to another bean (avoiding the older context lookup process). CDI enforces typing by eliminating string-based lookup so that the compiler can detect errors. CDI works very well with integrated development environments (IDE's).
The CDI event model allows beans to send events to one another without a compile-time dependency, and beans may create their own event payloads - a class that contains information pertinent to the event. Using CDI events, one bean can define the event, another can fire the event and a third can handle the event. And unlike with other event models, you can add listeners (observers) without registering them as listeners.
Duration: 45 minutes
Release Date: 14-JAN-2013
Created by: Tom McGinn
This multi-part series introduces you to the Java EE 6 Contexts and Dependency Injection feature.
Release Date: 20-JUN-12
Release Date: 24-MAR-11