Redbus 1.0.5

A simple in memory EventBus / MessageBus library in C#

There is a newer version of this package available.
See the version list below for details.
Install-Package Redbus -Version 1.0.5
dotnet add package Redbus --version 1.0.5
<PackageReference Include="Redbus" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Redbus --version 1.0.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

RedBus

A simple in memory EventBus / MessageBus library in C# with no dependencies

Build status

Nuget

Install-Package Redbus 

NuGet

Supported Frameworks

  • .NET Framework 4.5
  • .NET Standard 2.0

Example Usage

There is a generic PayloadEvent class that can be used, or you can use any custom classes that derive from EventBase


private void TestMethod()
{
  IEventBus eventBus = new EventBus();
  eventBus.Subscribe<PayloadEvent<int>>(OnIntEvent); 
  eventBus.Subscribe<CustomEventClass>(OnCustomEvent); 
  
  eventBus.Publish(new PayloadEvent<int>(5)); // OnIntEvent will be invoked
  eventBus.Publish(new CustomEventClass()); // OnCustomEvent will be invoked
  
  
  eventBus.Subscribe<PayloadEvent<string>>(s =>
  {
    Console.WriteLine(s.Payload);
  });
  
  eventBus.Publish(new PayloadEvent<string>("Hello"));
}

private void OnCustomEvent(CustomEventClass customEvent)
{
  Console.WriteLine("Received CustomEvent");
}

private void OnIntEvent(PayloadEvent<int> intEvent)
{
  Console.WriteLine(intEvent.Payload);
}

Note that RedBus does not have WeakReferences implemented, so you must explicitly call Unsubscribe for the event when disposing
the subscriber to avoid memory leaks. The Subscribe method returns a SubscriptionToken, this is used when unsubscribing.


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

eventBus.Unsubscribe(token);

Extensions


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

token.Unsubscribe(eventBus)

var payloadEvent = new PayloadEvent<string>("Hello");
payloadEvent.Publish(eventBus);

RedBus

A simple in memory EventBus / MessageBus library in C# with no dependencies

Build status

Nuget

Install-Package Redbus 

NuGet

Supported Frameworks

  • .NET Framework 4.5
  • .NET Standard 2.0

Example Usage

There is a generic PayloadEvent class that can be used, or you can use any custom classes that derive from EventBase


private void TestMethod()
{
  IEventBus eventBus = new EventBus();
  eventBus.Subscribe<PayloadEvent<int>>(OnIntEvent); 
  eventBus.Subscribe<CustomEventClass>(OnCustomEvent); 
  
  eventBus.Publish(new PayloadEvent<int>(5)); // OnIntEvent will be invoked
  eventBus.Publish(new CustomEventClass()); // OnCustomEvent will be invoked
  
  
  eventBus.Subscribe<PayloadEvent<string>>(s =>
  {
    Console.WriteLine(s.Payload);
  });
  
  eventBus.Publish(new PayloadEvent<string>("Hello"));
}

private void OnCustomEvent(CustomEventClass customEvent)
{
  Console.WriteLine("Received CustomEvent");
}

private void OnIntEvent(PayloadEvent<int> intEvent)
{
  Console.WriteLine(intEvent.Payload);
}

Note that RedBus does not have WeakReferences implemented, so you must explicitly call Unsubscribe for the event when disposing
the subscriber to avoid memory leaks. The Subscribe method returns a SubscriptionToken, this is used when unsubscribing.


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

eventBus.Unsubscribe(token);

Extensions


IEventBus eventBus = new EventBus();
var token = eventBus.Subscribe<PayloadEvent<string>>(s =>
{
  Console.WriteLine(s.Payload);
});

token.Unsubscribe(eventBus)

var payloadEvent = new PayloadEvent<string>("Hello");
payloadEvent.Publish(eventBus);

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.8 1,329 8/20/2019
1.0.7 262 6/10/2019
1.0.6 194 4/24/2019
1.0.5 2,487 8/9/2018
1.0.4 1,409 10/24/2017
1.0.3 1,093 3/31/2017
1.0.2 1,408 12/19/2015
1.0.0 484 12/19/2015