Darp.Utils.Messaging 1.13.0

dotnet add package Darp.Utils.Messaging --version 1.13.0
                    
NuGet\Install-Package Darp.Utils.Messaging -Version 1.13.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="Darp.Utils.Messaging" Version="1.13.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Darp.Utils.Messaging" Version="1.13.0" />
                    
Directory.Packages.props
<PackageReference Include="Darp.Utils.Messaging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Darp.Utils.Messaging --version 1.13.0
                    
#r "nuget: Darp.Utils.Messaging, 1.13.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.
#addin nuget:?package=Darp.Utils.Messaging&version=1.13.0
                    
Install Darp.Utils.Messaging as a Cake Addin
#tool nuget:?package=Darp.Utils.Messaging&version=1.13.0
                    
Install Darp.Utils.Messaging as a Cake Tool

<div align="center">

Darp.Utils.Messaging

NuGet Downloads

Dotnet Version Language Version

Tests License

A source generator to generate implementation for MessageSource and MessageSinks.

</div>

You should use this packet if you want

  • Events that can be subscribed to by a specific type
  • Support for ref-like messages (>= net9.0)
  • a very slim library

This package is not for you

  • need async handling
  • do not want source generation
  • additional features

Usage

The library is structured in two core roles:

  • MessageSource: A class which holds a list of subscribers that can be notified about a new message
  • MessageSink: A class which holds one or multiple handlers for specific message types

This library generates necessary boilerplate for those two roles and provides a few additional helpers.

MessageSource

A message source can be defined by adding the MessageSource attribute to a partial class. The source generator will generate a list of subscribers, a Subscribe method as well as a protected Publish method which can be used to notify subscribers about a new value

using Darp.Utils.Messaging;

[MessageSource]
public sealed partial class TestMessageSource
{
    public void PublishInt()
    {
        Publish(42);
    }
}

MessageSink

A message sink can be defined by adding a MessageSink attribute to any void method with only a single parameter. The source generator will generate a class which can be used to subscribe to any source and links the chosen method to those events.

using Darp.Utils.Messaging;

public sealed partial class TestClass
{
    [MessageSink]
    private void OnInt(int message) { }

    [MessageSink]
    private void OnSpan(System.ReadOnlySpan<byte> message) { }

    [MessageSink]
    private void OnAny<T>(T message) where T : allows ref struct { } // Add 'allows ref struct' only for >= net9.0
}

Helpers

A few helpers are predefined in the library. If you do not want to define a new class you can use the MessageSubject. Also, it is possible to Subscribe for a certain type directly or convert the source to an IObservable:

using Darp.Utils.Messaging;

var subject = new MessageSubject();

// Subscribe to any source and use the dispose method to unsubscribe
IDisposable disposable = source.Subscribe<int>(_ => {});
source.Subscribe<string>(_ => {});

// Convert to an IObservable and use with reactive overloads
IObservable observable = source.AsObservable<int>();

// Publish new values
subject.Publish("Some string");
subject.Publish(42);

You can take a look at the tests at test/Darp.Utils.Messaging.Generator.Verify for additional usage examples. Also, you can take a look at the expected generated code there.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.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 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.
  • .NETStandard 2.0

    • No dependencies.
  • net9.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.13.0 198 3/5/2025