Fork me on GitHub

Registration by Attribute

Registering events and event handler method with attributes is the simplest way to make events and event handler methods interact with the event broker. However, there exist scenarios where attributes are not sufficient because only compile-time constant values can be used in attribute definitions. For these dynamic scenarios see registration by event broker registrar.

Register Events and Handler Methods

The event broker listens to events with the attribute EventPublication and can call methods decorated with the EventSubscription attribute.

After registration on the event broker, fired events are routed to corresponding subscribers.

If you want to stop interaction with event broker, you can unregister the instance from the event broker.

Event Topics

The string defined in the attributes is used to uniquely identify the event topic. Subscribers get notified about events fired with the same topic.

Signature

The event broker can only listen to events with an event handler type EventHandler or EventHandler<TEventArgs> where TEventArgs : EventArgs. Other delegate types are not supported.

The signature of subscribers has to match the event handler type specified by the publication the subscriber listens to:

Handlers

You have to define how the event should be handled in the event subscription:

See documentation about handlers for a list of available handlers.

Handler Restrictions

Handler restrictions (see Handlers) can be defined in the EventPublication:

Matchers

Publication or subscription specific matchers (see Matchers) can be defined with the attributes:

Multiple Event Topics

You can fire multiple event topics or handle multiple event topics with a single event or event handler method: