ApplicationEventMethodAdapter class

An adapter class in Jetleaf that bridges ApplicationEvents with listener methods.

This class dynamically resolves the target pod and invokes a listener method when an event is published. It inspects method parameters and injects values based on type:

  • Supplies the ApplicationEvent itself if required.
  • Assigns default values for primitive parameters.
  • Resolves complex dependencies from a PodFactory.

Example

// Assume we have a custom ApplicationEvent
class UserCreatedEvent extends ApplicationEvent {
  final String userId;
  UserCreatedEvent(this.userId);
}

// A pod class with an event handler method
class UserEventHandler {
  void handleUserCreated(UserCreatedEvent event) {
    print('User created with ID: ${event.userId}');
  }
}

// Register the adapter
final podFactory = MyPodFactory();
final method = Method(UserEventHandler, 'handleUserCreated');
final adapter = ApplicationEventMethodAdapter(
  Class<UserCreatedEvent>(),
  'userEventHandlerPod',
  method,
  podFactory,
);

// Later, when the event is published, the adapter will:
// - resolve the `UserEventHandler` pod
// - inject the `UserCreatedEvent`
// - invoke `handleUserCreated`
await adapter.onApplicationEvent(UserCreatedEvent('abc123'));
Implemented types

Constructors

ApplicationEventMethodAdapter(Class? _eventClass, String _podName, Method _method, ConfigurableListablePodFactory _podFactory)

Properties

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

Methods

getOrder() → int
A contract for objects that are assigned an order or precedence value.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onApplicationEvent(ApplicationEvent event) → Future<void>
Handle an application event of type E.
override
supportsEventOf(ApplicationEvent event) → bool
Returns true if the listener supports the given event.
override
toString() → String
A string representation of this object.
inherited

Operators

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