Class MessageBus
- Namespace
- ReactiveUI
- Assembly
- ReactiveUI.dll
MessageBus 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.
- Inheritance
-
Message
Bus
- Implements
-
IEnable
Logger
- Extension Methods
Constructors
MessageBus()
Properties
Current
Gets or sets the Current MessageBus.
Property Value
Methods
IsRegistered(Type, string?)
Determines if a particular message Type is registered.
Parameters
typeTypeThe Type of the message to listen to.
contractstringA 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?)
Listen provides an Observable that will fire whenever a Message is provided for this object via RegisterMessageSource or SendMessage.
Parameters
contractstringA 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
TThe 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.
Parameters
contractstringA 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
TThe 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.
Parameters
sourceIObservable<T>An Observable that will be subscribed to, and a message sent out for each value provided.
contractstringA 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
TThe 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.
Parameters
schedulerISchedulerThe scheduler on which to post the notifications for the specified type and contract. CurrentThreadScheduler by default.
contractstringA 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
TThe 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.
Parameters
messageTThe actual message to send.
contractstringA 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
TThe type of the message to send.