LightMessageBus 1.0.1
See the version list below for details.
dotnet add package LightMessageBus --version 1.0.1
NuGet\Install-Package LightMessageBus -Version 1.0.1
<PackageReference Include="LightMessageBus" Version="1.0.1" />
paket add LightMessageBus --version 1.0.1
#r "nuget: LightMessageBus, 1.0.1"
// 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.
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.
BUGFIX - fixed case when within publish a new subscriber was added