A simple event bus for .NET

chikak picture chikak · Dec 15, 2008 · Viewed 36.6k times · Source

I want to make a very simple event bus which will allow any client to subscribe to a particular type of event and when any publisher pushes an event on the bus using EventBus.PushEvent() method only the clients that subscribed to that particular event type will get the event.

I am using C# and .NET 2.0.

Answer

Sean Kearon picture Sean Kearon · Dec 19, 2011

Tiny Messenger is a good choice, I've been using it in a live project for 2.5 years now. Some code examples from the Wiki (link below):

Publishing

messageHub.Publish(new MyMessage());

Subscribing

messageHub.Subscribe<MyMessage>((m) => { MessageBox.Show("Message Received!"); });
messageHub.Subscribe<MyMessageAgain>((m) => { MessageBox.Show("Message Received!"); }, (m) => m.Content == "Testing");

The code's on GitHub: https://github.com/grumpydev/TinyMessenger

The Wiki is here: https://github.com/grumpydev/TinyMessenger/wiki

It has a Nuget package also

Install-Package TinyMessenger