LightMessageBus 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package LightMessageBus --version 1.0.1                
NuGet\Install-Package LightMessageBus -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LightMessageBus" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LightMessageBus --version 1.0.1                
#r "nuget: LightMessageBus, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LightMessageBus as a Cake Addin
#addin nuget:?package=LightMessageBus&version=1.0.1

// Install LightMessageBus as a Cake Tool
#tool nuget:?package=LightMessageBus&version=1.0.1                

What is LightMessageBus?

A simple, light-weight application level event aggregator which facilitates the exchange of messages between objects without direct references.

Use-cases and examples?

A soundComponent needs to be notified whenever a user clicks on any button.

MessageBus.Default.FromAny().Where<ButtonClickMessage>().Notify(soundComponent)

A taxCalculator needs to be notified whenever shopping cart is changed.

MessageBus.Default.From(shoppingCart).Notify(taxCalculator);

How is this achieved?

LightMessageBus uses a simple publisher/subscriber pattern.

  • Subscribers use the MessageBus to subscribe to messages they wish to be notified about. They may wish to filter messages by the source, type of message or some other predicate.
  • Publishers use the MessageBus to publish messages to the potential subscribers
  • Neither subscribers nor publishers have any references to each other. They simply use a common communication channel - the MessageBus

How does that help?

The pub/sub pattern enables you to promote decoupled architecture in your application. Since there is no need for various objects (views, models, controllers, ...) to know of each other existence - you are free to develop them independently in isolation. Such architecture enables testing, refactoring and limits the propagation of changes through the system.

Why not use delegates/events?

Using delegates and/or events requires a reference between the publisher and the subscriber (subscribers reference publishers or vice-versa). Any change to the referenced class will affect the other. Such change may even propagate through the system resulting in significant changes due to a small cause.

How is it used?

LightMessageBus uses LINQ-like, fluent syntax for maximum readability and flexibility. The basic building blocks of a LightMessageBus registration expression are: From, Where and Notify.

First we define the publishers:

  • From - specifies publisher(s) of interest to subscriber.
  • FromAny - specifies any publisher.

Next we optionally define the messages:

  • Where - specifies the types of messages of interest to subscriber.

Lastly we define the subscriber:

  • Notify - specifies the subscriber.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 767 9/10/2021
1.0.1 4,520 5/25/2016
1.0.0 1,422 9/19/2014

BUGFIX - fixed case when within publish a new subscriber was added