This project is read-only.

Subscribe extension method

Subscribes the caller instance to an event with specified ID.

Subscribe extension method signature
public static EventMessageHandler Subscribe(this object eventSource, EventHub eventHub, int id, Action<EventMessage> handler)

Input arguments
  • eventSource is an instance of the object, which provides the event handler
  • eventHub is an object that manages event messaging
  • id is an event message identifier
  • handler is an event message handler
Return value
  • eventMessageHandler is an instance of the EventMessageHandler class


Subscribe MainWindow to EventId.Default.Dispatch event ID and use HandleDispatch method as event message handler.

Get message parameter "Dispatch" and use its value as an Action delegate to invoke a method in the Dispatcher.

using System.Windows;
using EventAggregator;

namespace EventAggregatorSample
    public partial class MainWindow : Window
        public MainWindow()

            this.Subscribe(EventId.Default.Dispatch, HandleDispatch);

        private void HandleDispatch(EventMessage eventMessage)

Last edited Apr 19, 2012 at 7:17 PM by DarkVasya, version 6


No comments yet.