PicoBus 0.0.5
dotnet add package PicoBus --version 0.0.5
NuGet\Install-Package PicoBus -Version 0.0.5
<PackageReference Include="PicoBus" Version="0.0.5" />
<PackageVersion Include="PicoBus" Version="0.0.5" />
<PackageReference Include="PicoBus" />
paket add PicoBus --version 0.0.5
#r "nuget: PicoBus, 0.0.5"
#:package PicoBus@0.0.5
#addin nuget:?package=PicoBus&version=0.0.5
#tool nuget:?package=PicoBus&version=0.0.5
PicoBus
A lightweight, thread-safe, in-memory event bus for .NET β designed for simplicity, minimal overhead, and zero dependencies.
PicoBus allows decoupled communication between components in your application through an intuitive publish/subscribe model.
π Features
- Light & dependency-free β no external libraries used or required.
- Thread-safe using minimal locking.
- Fluent API for clean and expressive subscriptions.
- Tiny footprint β a few hundred lines of C# code.
π¦ Installation
You can include this in your project manually or via a NuGet package (if you publish it):
dotnet add package PicoBus
Or clone and reference it locally:
git clone https://github.com/paulpeters144/PicoBus.git
π‘ Quick Start
Hereβs a simple example showing how to use PicoBus to publish and subscribe to events:
using PicoBus;
// Create the event bus
var bus = PicoBusFactory.New();
// 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
PicoBus 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
// Define the event as a simple, immutable record
public record StatusUpdate(string NewStatus);
var bus = PicoBusFactory.New();
var statusEvent = new StatusUpdate("System Online");
// Handler A subscribes and processes the event
var serviceSub1 = bus.CreateSub<StatusUpdate>();
serviceSub1.OnMessage(e =>
{
Console.WriteLine($"[Service 1] Received: {e.NewStatus}");
});
// Handler B subscribes and processes the same event
var serviceSub2 = bus.CreateSub<StatusUpdate>();
serviceSub2.OnMessage(e =>
{
Console.WriteLine($"[Service 2] Logging change...");
});
// Publish the single event
bus.Fire(statusEvent);
Output:
[Service 1] Received: System Online
[Service 2] Logging change...
π§ Design Philosophy
PicoBus 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.