
上QQ阅读APP看书,第一时间看更新
Events
CDI supports events. A bean can send an event representable by a simple POJO and another bean can receive it and execute the next operation tied to it. An event is a good manner to decoupling of the code because it works with transversal classes. The Event interface is used to inject the events with any bean we want.
Here's a simple event object:
public class Bill {
...
}
It can be injected in any bean:
@Inject
private Event<Bill> billEvent;
It can also be started:
Bill bill = new Bill();
bill.setId(0);
bill.setTitle("ticket for the concert of Franco Battiato");
billEvent.fire(bill);