hendryluk / cormo

.NET Application Framework based on Spring and Java EE CDI
MIT License
5 stars 4 forks source link

Events: Transactional Observers #15

Open hendryluk opened 9 years ago

hendryluk commented 9 years ago

Expanding on https://github.com/hendryluk/cormo/issues/7

CDI spec allows you to specify that a particular observer should receive event notifications during the before or after completion phase of the transaction in which the event was raised. I.e. it defers the notifications of an event until the intended phase of the transaction has been reached (as opposed to the current implementation that only allows immediate notifications). Ref: https://docs.jboss.org/weld/reference/latest/en-US/html/events.html#_transactional_observers

Supported options are:

Example

public void OnLoggedIn([Observes(During=TransactionPhase.AfterSuccess)] LoggedIn evt)
{
   /* handles */
}

This is important e.g. in scenario where you want to send an outbound customer email only after the transaction has been successfully committed.