Click or drag to resize

IMessageBus Interface

Brings possibility to communicate between modules not knowing each other.

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

The IMessageBus type exposes the following members.

Methods
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