Interface IMessageBus
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
IMessageBus represents an object that can act as a "Message Bus", a simple way for ViewModels and other objects to communicate with each other in a loosely coupled way.
Specifying which messages go where is done via a combination of the Type of the message as well as an additional "Contract" parameter; this is a unique string used to distinguish between messages of the same Type, and is arbitrarily set by the client.
public interface IMessageBus : IEnableLogger
Methods
IsRegistered(Type, string?)
Determines if a particular message Type is registered.
bool IsRegistered(Type type, string? contract = null)
Parameters
type
TypeThe type of the message.
contract
stringA unique string to distinguish messages with identical types (i.e. "MyCoolViewModel") - if the message type is only used for one purpose, leave this as null.
Returns
- bool
True if messages have been posted for this message Type.
ListenIncludeLatest<T>(string?)
ListenIncludeLatest provides an Observable that will fire whenever a Message is provided for this object via RegisterMessageSource or SendMessage and fire the last provided Message immediately if applicable, or null.
IObservable<T> ListenIncludeLatest<T>(string? contract = null)
Parameters
contract
stringA unique string to distinguish messages with identical types (i.e. "MyCoolViewModel") - if the message type is only used for one purpose, leave this as null.
Returns
- IObservable<T>
An Observable representing the notifications posted to the message bus.
Type Parameters
T
The type of the message to listen to.
Listen<T>(string?)
Listen provides an Observable that will fire whenever a Message is provided for this object via RegisterMessageSource or SendMessage.
IObservable<T> Listen<T>(string? contract = null)
Parameters
contract
stringA unique string to distinguish messages with identical types (i.e. "MyCoolViewModel") - if the message type is only used for one purpose, leave this as null.
Returns
- IObservable<T>
An observable sequence.
Type Parameters
T
The type of the message to listen to.
RegisterMessageSource<T>(IObservable<T>, string?)
Registers an Observable representing the stream of messages to send. Another part of the code can then call Listen to retrieve this Observable.
IDisposable RegisterMessageSource<T>(IObservable<T> source, string? contract = null)
Parameters
source
IObservable<T>An Observable that will be subscribed to, and a message sent out for each value provided.
contract
stringA unique string to distinguish messages with identical types (i.e. "MyCoolViewModel") - if the message type is only used for one purpose, leave this as null.
Returns
- IDisposable
A disposable.
Type Parameters
T
The type of the message to listen to.
RegisterScheduler<T>(IScheduler, string?)
Registers a scheduler for the type, which may be specified at runtime, and the contract.
void RegisterScheduler<T>(IScheduler scheduler, string? contract = null)
Parameters
scheduler
ISchedulerThe scheduler on which to post the notifications for the specified type and contract. CurrentThreadScheduler by default.
contract
stringA unique string to distinguish messages with identical types (i.e. "MyCoolViewModel") - if the message type is only used for one purpose, leave this as null.
Type Parameters
T
The type of the message to listen to.
Remarks
If a scheduler is already registered for the specified runtime and contract, this will overwrite the existing registration.
SendMessage<T>(T, string?)
Sends a single message using the specified Type and contract. Consider using RegisterMessageSource instead if you will be sending messages in response to other changes such as property changes or events.
void SendMessage<T>(T message, string? contract = null)
Parameters
message
TThe actual message to send.
contract
stringA unique string to distinguish messages with identical types (i.e. "MyCoolViewModel") - if the message type is only used for one purpose, leave this as null.
Type Parameters
T
The type of the message to send.