# ApplicationEventBusAware class abstract interface

🫘 Interface for components that need access to the ApplicationEventBus.

The ApplicationEventBusAware interface provides components with direct access to the application's event bus for publishing and subscribing to application events in an event-driven architecture.

### Event-Driven Architecture Benefits:

- Loose Coupling: Components communicate through events without direct dependencies
- Asynchronous Processing: Support for async event handling
- Extensibility: Easy to add new event listeners without modifying publishers
- Audit Trail: Events provide natural audit points in system behavior

### Framework Integration:

- Called during component initialization when event bus is available
- The event bus may be null if event system is disabled
- Events are typically processed synchronously in the calling thread

### Example Usage:

    @Component
    class OrderService implements ApplicationEventBusAware {
      ApplicationEventBus? _eventBus;

      @override
      void setApplicationEventBus(ApplicationEventBus? applicationEventBus) {
        _eventBus = applicationEventBus;
      }

      Future<Order> createOrder(OrderRequest request) async {
        final order = Order.fromRequest(request);

        // Publish domain event
        _eventBus?.publish(OrderCreatedEvent(this, order));

        // Publish integration event
        _eventBus?.publish(OrderPlacedEvent(this, order));

        return order;
      }

      void subscribeToPaymentEvents() {
        _eventBus?.subscribe<PaymentReceivedEvent>((event) {
          _fulfillOrder(event.orderId);
        });
      }
    }

### Best Practices:

- Use domain events for business logic, system events for technical concerns
- Keep event objects immutable and serializable
- Consider event ordering and idempotency in distributed systems
- Use `@EventListener` annotation for simpler event handling when possible

See also:

- ApplicationEventBus for the event bus interface
- ApplicationEvent for base event class
- ApplicationContextAware for alternative event publishing via context

## Properties

hashCode → int
  The hash code for this object.
  no setter inherited
runtimeType → Type
  A representation of the runtime type of the object.
  no setter inherited

## Methods

noSuchMethod(Invocation invocation) → dynamic
  Invoked when a nonexistent method or property is accessed.
  inherited
setApplicationEventBus(ApplicationEventBus? applicationEventBus) → void
  Sets the ApplicationEventBus that this component can use for event operations.
toString() → String
  A string representation of this object.
  inherited

## Operators

operator ==(Object other) → bool
  The equality operator.
  inherited