PicoBus 0.0.5

dotnet add package PicoBus --version 0.0.5
                    
NuGet\Install-Package PicoBus -Version 0.0.5
                    
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="PicoBus" Version="0.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PicoBus" Version="0.0.5" />
                    
Directory.Packages.props
<PackageReference Include="PicoBus" />
                    
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 PicoBus --version 0.0.5
                    
#r "nuget: PicoBus, 0.0.5"
                    
#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.
#:package PicoBus@0.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PicoBus&version=0.0.5
                    
Install as a Cake Addin
#tool nuget:?package=PicoBus&version=0.0.5
                    
Install as a Cake Tool

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:

  1. Sets IsActive to false.
  2. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.5 163 10/12/2025
0.0.4 130 10/10/2025
0.0.3 122 10/10/2025
0.0.2 119 10/10/2025
0.0.1 123 10/10/2025