IMessenger
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.
Methods
public void Cleanup()
iMessenger.Cleanup()
Drops dead recipient references (relevant for weak messengers).
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.
Returns: true if registered.
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.
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.
Returns: The same message instance (after delivery), enabling request/response patterns.
public void UnregisterAll(object recipient)
iMessenger.UnregisterAll(recipient)
Unregisters a recipient from every message type and token.
- recipient
- The recipient.
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.