initializeApplicationEventBus method

  1. @protected
  2. @mustCallSuper
Future<void> initializeApplicationEventBus()

Initializes the ApplicationEventBus for this context.

This sets up the event publishing system. By default, it creates a SimpleApplicationEventBus and registers it in the pod factory. Subclasses may override this to supply a custom implementation.

This is part of Jetleaf – a framework which developers can use to build web applications.

Implementation

@protected
@mustCallSuper
Future<void> initializeApplicationEventBus() async {
  final factory = getPodFactory();

  if (await factory.containsLocalPod(APPLICATION_EVENT_BUS_POD_NAME)) {
    _applicationEventBus = await factory.getPod<ApplicationEventBus>(APPLICATION_EVENT_BUS_POD_NAME);

    if (logger.getIsTraceEnabled()) {
      logger.trace("Using application event bus ${_applicationEventBus!.runtimeType}");
    }
  } else {
    final aeb = Class<SimpleApplicationEventBus>(null, PackageNames.CORE);
    _applicationEventBus = SimpleApplicationEventBus(factory);

    await factory.registerSingleton(
      APPLICATION_EVENT_BUS_POD_NAME,
      aeb,
      object: ObjectHolder<ApplicationEventBus>(
        _applicationEventBus!,
        packageName: PackageNames.CORE,
        qualifiedName: aeb.getQualifiedName(),
      ),
    );

    if (logger.getIsTraceEnabled()) {
      logger.trace("No application event bus found, using default application event bus ${_applicationEventBus!.runtimeType}");
    }
  }

  return Future.value();
}