Page MenuHomePhabricator

Add support for wiring files for domain events
Closed, DeclinedPublic

Description

Domain events can be used inside MediaWiki core to remove the need for code that updates state to know about other code that needs to be notified about this update (this is just the standard listener pattern).

Knowledge of which part of the code needs to listen to which event should be located in the application's "wiring". This could be done as part of the application's service wiring - however, this approach is not attractive: it would mean that we have to register all listeners for all events in the service instantiator for DomainEventDispatcher.

It seems better to establish a separate wiring system for events, as follows:

  • each event wiring file returns an associative array that maps even types to wiring callbacks
  • a wiring callback associated with an event type returns a list of listeners that is to be registered for that event type
  • DomainEventDispatcher maintains a wiring map, associating event types with lists of callbacks.
  • DomainEventDispatcher gets a loadWiringFile() method which merges the map returned by the wiring file with any previously loaded wiring.
  • When the first event of a gioven type is triggered, any wiring callbacks registered for that event type will be invoked, and all listeners returned by any of the callbacks are registered for the event type before the event is triggered. The wiring for that event type is then reset.

This way, listener instantiation is deferred until the listeners are first needed. Also, all listeners for a given type of event can be defined in a single place.

Event Timeline

Change #1069670 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] MediaWikiServices: introduce event wiring support

https://gerrit.wikimedia.org/r/1069670

Change #1069670 abandoned by Daniel Kinzler:

[mediawiki/core@master] MediaWikiServices: introduce event wiring support

Reason:

obsolete

https://gerrit.wikimedia.org/r/1069670

We decided to go with the subsciber patter, which provides a natural way of wiring core components. See the ChangeTrackingEventIngress class for an example.

  NODES
Note 1
Project 3