Table of Contents

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

objectToSend T

The message to send.

key string

An optional key that selects the channel; null means the default channel.

Type Parameters

T

The 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

action Action<T>

The action to invoke when a message is published.

key string

An optional key that narrows the subscription to a channel; null means the default channel.

Type Parameters

T

The 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

action Action<T>

The action to remove.

key string

The key the action was subscribed with.

Type Parameters

T

The message type.