How to handle events in the application context