Click or drag to resize

MessageBus Class

Brings possibility to communicate between modules not knowing each other.
Inheritance Hierarchy
SystemObject
  SniffCore.MediationMessageBus

Namespace:  SniffCore.Mediation
Assembly:  SniffCore.Mediation (in SniffCore.Mediation.dll) Version: 2.0.0
Syntax
C#
public class MessageBus : IMessageBus

The MessageBus type exposes the following members.

Constructors
  NameDescription
Public methodMessageBus
Creates a new instance of MessageBus.
Top
Methods
Extension Methods
  NameDescription
Public Extension MethodIsNullOrEmpty
Checks if the object is null or an empty string.
(Defined by ObjectEx.)
Public Extension MethodIsNullOrWhiteSpace
Checks if the object is null, an empty string or a string which consists of whitespace (or tabs) only.
(Defined by ObjectEx.)
Top
Examples
C#
public class Bootstrapper
{
    public void InitContainer()
    {
        _unityContainer.RegisterSingleton<IMessageBus, MessageBus>();
    }
}

public class ViewModel : ObservableObject, IDisposable
{
    private List<ISubscriber> _subscribers;

    public ViewModel(IMessageBus messageBus)
    {
        _subscribers = new List<ISubscriber>
        {
            messageBus.Subscribe<string>(OnStringReceived),
            messageBus.Subscribe<int>(OnIntReceived).On(Dispatcher.CurrentDispatcher)
        };
    }

    private void OnStringReceived(string parameter)
    {
    }

    private void OnIntReceived(int parameter)
    {
    }

    public void Dispose()
    {
        _subscribers.ForEach(x => x.Dispose());
    }
}

public class OtherViewModel : ObservableObject
{
    private IMessageBus _messageBus;

    public ViewModel(IMessageBus messageBus)
    {
        _messageBus = messageBus;
    }

    public void Publish()
    {
        _target.Publish("Steve");
        _target.Publish(13);
    }
}
See Also