Darp.Utils.Messaging
1.19.2
dotnet add package Darp.Utils.Messaging --version 1.19.2
NuGet\Install-Package Darp.Utils.Messaging -Version 1.19.2
<PackageReference Include="Darp.Utils.Messaging" Version="1.19.2" />
<PackageVersion Include="Darp.Utils.Messaging" Version="1.19.2" />
<PackageReference Include="Darp.Utils.Messaging" />
paket add Darp.Utils.Messaging --version 1.19.2
#r "nuget: Darp.Utils.Messaging, 1.19.2"
#:package Darp.Utils.Messaging@1.19.2
#addin nuget:?package=Darp.Utils.Messaging&version=1.19.2
#tool nuget:?package=Darp.Utils.Messaging&version=1.19.2
<div align="center">
Darp.Utils.Messaging
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
- require support for ref-like messages (>= net9.0)
- want a very slim library
- have a few, long-living subscribers with a high message throughput
- have a lot of different message types
This package is not for you if you
- need async handling
- do not want source generation
- additional features
- have thousands of subscribers at once that are not expecting an event
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 messageMessageSink: 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()
{
PublishMessage(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 TestMessageSink
{
[MessageSink]
private void OnInt(int message) => Console.WriteLine($"Received '{message}'");
[MessageSink]
private void OnSpan(System.ReadOnlySpan<byte> message) { }
// Handle any message that was not handled by any other method
[MessageSink]
private void OnAny<T>(T message) where T : allows ref struct { } // Add 'allows ref struct' only for >= net9.0
}
This sink can now be subscribed to the previously defined source.
var source = new TestMessageSource();
source.Subscribe(new TestMessageSink());
source.PublishInt();
// Output: Received '42'
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.
TODO
- DisposableBags
- Analyzers
- Evaluate filters
- Return bool/int whether publish was handled
| Product | Versions 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- System.Collections.Immutable (>= 9.0.0)
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Darp.Utils.Messaging:
| Package | Downloads |
|---|---|
|
Darp.Ble.Hci
Abstraction for BLE implementations |
|
|
Darp.Ble.HciHost
Abstraction for BLE implementations |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.19.2 | 569 | 10/24/2025 |
| 1.19.1 | 377 | 7/28/2025 |
| 1.19.0 | 156 | 7/27/2025 |
| 1.18.2 | 179 | 7/10/2025 |
| 1.18.1 | 181 | 7/7/2025 |
| 1.18.0 | 333 | 6/29/2025 |
| 1.17.4 | 129 | 6/28/2025 |
| 1.17.3 | 307 | 6/13/2025 |
| 1.17.2 | 318 | 6/12/2025 |
| 1.17.1 | 324 | 6/12/2025 |
| 1.17.0 | 332 | 6/8/2025 |
| 1.16.1 | 179 | 6/3/2025 |
| 1.16.0 | 110 | 5/24/2025 |
| 1.15.0 | 114 | 5/24/2025 |
| 1.14.3 | 187 | 5/22/2025 |
| 1.14.2 | 180 | 5/22/2025 |
| 1.14.1 | 180 | 5/20/2025 |
| 1.14.0 | 183 | 5/20/2025 |
| 1.13.2 | 174 | 5/19/2025 |
| 1.13.1 | 187 | 5/19/2025 |
| 1.13.0 | 274 | 3/5/2025 |