IMessenger

Ecng.ComponentModel

A loosely-coupled message bus: recipients register for a message type (optionally scoped by a token) and senders broadcast messages without referencing the recipients. The shape mirrors the commonly used surface of CommunityToolkit.Mvvm.Messaging.IMessenger.

Methoden

Cleanup
public void Cleanup()
iMessenger.Cleanup()

Drops dead recipient references (relevant for weak messengers).

IsRegistered``1
public bool IsRegistered<TMessage>(object recipient, object token)
result = iMessenger.IsRegistered(recipient, token)

Determines whether a recipient is registered for a message type and token.

recipient
The recipient.
token
The channel token.

Rückgabe: true if registered.

Register``2
public void Register<TRecipient, TMessage>(TRecipient recipient, object token, MessageHandler<TRecipient, TMessage> handler)
iMessenger.Register(recipient, token, handler)

Registers a recipient for a given message type and token.

recipient
The recipient.
token
The channel token (use Object equality to match sends).
handler
The handler invoked on broadcast.
Reset
public void Reset()
iMessenger.Reset()

Removes all registrations.

Send``1
public TMessage Send<TMessage>(TMessage message, object token)
result = iMessenger.Send(message, token)

Broadcasts a message to all recipients registered for its type and the given token.

message
The message.
token
The channel token.

Rückgabe: The same message instance (after delivery), enabling request/response patterns.

UnregisterAll
public void UnregisterAll(object recipient)
iMessenger.UnregisterAll(recipient)

Unregisters a recipient from every message type and token.

recipient
The recipient.
Unregister``1
public void Unregister<TMessage>(object recipient, object token)
iMessenger.Unregister(recipient, token)

Unregisters a recipient from a message type and token.

recipient
The recipient.
token
The channel token.