NanoBus.Core
0.0.1
dotnet add package NanoBus.Core --version 0.0.1
NuGet\Install-Package NanoBus.Core -Version 0.0.1
<PackageReference Include="NanoBus.Core" Version="0.0.1" />
<PackageVersion Include="NanoBus.Core" Version="0.0.1" />
<PackageReference Include="NanoBus.Core" />
paket add NanoBus.Core --version 0.0.1
#r "nuget: NanoBus.Core, 0.0.1"
#:package NanoBus.Core@0.0.1
#addin nuget:?package=NanoBus.Core&version=0.0.1
#tool nuget:?package=NanoBus.Core&version=0.0.1
NanoBus.Core
A lightweight, thread-safe, in-memory event bus for .NET β designed for simplicity, minimal overhead, and zero dependencies.
NanoBus allows decoupled communication between components in your application through an intuitive publish/subscribe model.
π Features
- In-memory & dependency-free β no external libraries required.
- Thread-safe using
ConcurrentDictionaryand minimal locking. - Fluent API for clean and expressive subscriptions.
- Automatic subscription cleanup via
Dispose(). - Tiny footprint β a few hundred lines of well-documented C# code.
π¦ Installation
You can include this in your project manually or via a NuGet package (if you publish it):
dotnet add package NanoBus.Core
Or clone and reference it locally:
git clone https://github.com/yourusername/NanoBus.Core.git
π‘ Quick Start
Hereβs a simple example showing how to use NanoBus to publish and subscribe to events:
using NanoBus.Core;
// Create the event bus
var bus = new NanoBus();
// Define an event type
public class OrderPlaced
{
public string OrderId { get; set; } = string.Empty;
}
// Subscribe to the event
var subscription = bus.CreateSub<OrderPlaced>();
subscription.OnMessage(order =>
{
Console.WriteLine($"Order received: {order.OrderId}");
});
// Publish an event
bus.Fire(new OrderPlaced { OrderId = "ORD-001" });
// Unsubscribe when done
subscription.Dispose();
Output:
Order received: ORD-001
βοΈ API Overview
IEventBus
| Member | Description |
|---|---|
int SubCount |
Gets the total number of active subscriptions. |
Subscription<TEvent> CreateSub<TEvent>() |
Creates a new subscription for the specified event type. |
void Fire<TEvent>(TEvent eventData) |
Publishes an event to all subscribers of that type. |
Subscription<TEvent>
| Member | Description |
|---|---|
Guid Id |
Unique identifier for this subscription. |
bool IsActive |
Indicates whether the subscription is still active. |
OnMessage(Action<TEvent> handler) |
Sets the message handler using a fluent interface. |
Dispose() |
Deactivates the subscription and removes it from the bus. |
π§© Thread Safety
NanoBus ensures safe concurrent publishing and subscribing across multiple threads.
π§Ή Lifecycle Management
Each subscription is automatically tracked.
When you call Dispose() on a Subscription<TEvent>, it:
- Sets
IsActivetofalse. - Removes the subscription from the internal dictionary.
This ensures your application won't leak handlers over time.
π§ͺ Example: Multiple Subscribers
var bus = new NanoBus();
bus.CreateSub<string>().OnMessage(msg => Console.WriteLine($"Handler A: {msg}"));
bus.CreateSub<string>().OnMessage(msg => Console.WriteLine($"Handler B: {msg}"));
bus.Fire("Hello, NanoBus!");
Output:
Handler A: Hello, NanoBus!
Handler B: Hello, NanoBus!
π§ Design Philosophy
NanoBus is intentionally minimalist β designed for small services, background workers, and local message-passing between components where introducing a full-blown event system (like MediatR, MassTransit, or Kafka) would be excessive.
Itβs not meant to replace distributed message buses β itβs a micro bus for in-memory, single-process event delivery.
π License
MIT License
Copyright (c) 2025 Paul Q. Peters
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 was computed. 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. |
-
net8.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 |
|---|---|---|
| 0.0.1 | 226 | 10/10/2025 |