SimpleMessageHub 1.1.0-beta.0

This is a prerelease version of SimpleMessageHub.
dotnet add package SimpleMessageHub --version 1.1.0-beta.0
NuGet\Install-Package SimpleMessageHub -Version 1.1.0-beta.0
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="SimpleMessageHub" Version="1.1.0-beta.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleMessageHub --version 1.1.0-beta.0
#r "nuget: SimpleMessageHub, 1.1.0-beta.0"
#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 SimpleMessageHub as a Cake Addin
#addin nuget:?package=SimpleMessageHub&version=1.1.0-beta.0&prerelease

// Install SimpleMessageHub as a Cake Tool
#tool nuget:?package=SimpleMessageHub&version=1.1.0-beta.0&prerelease

SimpleMessageHub

main

Super simple and low volume message bus for smaller apps and utilities. Does not include automatic unsubscribing or use of weak references. If you expect a high volume of unsubscribed messages then you may wish to use a more mature library.

Overview

This is a simple messagebus class written in C# for dotnet 5.0. The class uses in internal dictionary to track observers of a message by its CLR type. Each entry in the dictionary is a list of subscription objects that are made up of a subscription token [Guid] and the action to execute [Action<TMessage>].

The main interface is IMessageBus which covers the following general use cases:

  1. Subscribing to a type of message with a delegate handler that accepts the message as its parameter.
  2. Publishing a message to all subscribers.
  3. Unsubscribing from a message type using the subscription token returned from the subscribe call.

Usage

Subscribe

The following syntax can be used to subscribe to a message. Assuming there is an existing message class: TestMessage : IMessage

var _messageBus = MessageBus.Default;
var handledCount = 0;
var token = _messageBus.Subscribe<TestMessage>(msg => handledCount++);
Publish

Continuing with our TestMessage class example we can publish the message in order to have the handlers executed.

var _messageBus = MessageBus.Default;
var msg1 = new TestMessage { Message = "Some message content." };
_messageHub.Publish(msg1)
Unsubscribe

You then should unsubscribe to the message when no longer concerned with its publishing. Unsubscribing is not automatic.

var _messageBus = MessageBus.Default;
_messageBus.Unsubscribe(token);   // token returned from sub call
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net35 is compatible.  net40 was computed.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 3.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • 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.1.0-beta.0 77 5/8/2023

Package Release to Nuget.org