Class EventAggregator
- Namespace
- EasySoftware.MvvmMini
- Assembly
- EasySoftware.MvvmMini.dll
Default thread-safe implementation of IEventAggregator.
public class EventAggregator : IEventAggregator
- Inheritance
-
EventAggregator
- Implements
- Inherited Members
Remarks
Subscribers are held through weak references, so a subscription does not keep its target object alive. Use methods of a long-lived object as handlers. A lambda that captures local variables is owned only by the delegate and can be garbage collected, which silently ends the subscription.
Constructors
EventAggregator()
Initializes a new instance of the EventAggregator class with no subscriptions.
public EventAggregator()
Methods
Publish<T>(T, string)
Publishes a message to all subscribers of type T and the given key.
public void Publish<T>(T objectToSend, string key = null)
Parameters
objectToSendTThe message to send.
keystringAn optional key that selects the channel; null means the default channel.
Type Parameters
TThe message type.
Reset()
Removes all subscriptions.
public void Reset()
Subscribe<T>(Action<T>, string)
Subscribes an action to messages of type T.
public void Subscribe<T>(Action<T> action, string key = null)
Parameters
actionAction<T>The action to invoke when a message is published.
keystringAn optional key that narrows the subscription to a channel; null means the default channel.
Type Parameters
TThe message type.
Unsubscribe<T>(Action<T>, string)
Removes a subscription that was added with Subscribe<T>(Action<T>, string).
public void Unsubscribe<T>(Action<T> action, string key = null)
Parameters
Type Parameters
TThe message type.