getApplicationEventBus method
Returns the ApplicationEventBus currently associated with this application context.
The event bus enables publish-subscribe communication patterns throughout the application, promoting loose coupling between components.
Example:
// Access event bus for manual event publishing
final eventBus = context.getApplicationEventBus();
// Publish application lifecycle events
eventBus.publish(ApplicationStartedEvent(context));
// Publish domain events
eventBus.publish(UserRegisteredEvent(user));
eventBus.publish(PaymentReceivedEvent(payment));
// Publish system events
eventBus.publish(CacheClearedEvent());
eventBus.publish(ConfigurationUpdatedEvent(newConfig));
// Register listeners programmatically
eventBus.subscribe<OrderShippedEvent>((event) {
trackingService.updateShipmentStatus(event.orderId, event.trackingNumber);
});
Implementation
@override
ApplicationEventBus getApplicationEventBus() {
if(_applicationEventBus == null) {
throw IllegalStateException("Cannot access application event bus since it has not been initialized yet.");
}
return _applicationEventBus!;
}