SharpEventBus 2.0.0

dotnet add package SharpEventBus --version 2.0.0
                    
NuGet\Install-Package SharpEventBus -Version 2.0.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="SharpEventBus" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpEventBus" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SharpEventBus" />
                    
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 SharpEventBus --version 2.0.0
                    
#r "nuget: SharpEventBus, 2.0.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=SharpEventBus&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SharpEventBus&version=2.0.0
                    
Install as a Cake Tool

SharpEventBus

A simple, lightweight, in-memory event bus library for modern .NET applications.

Overview

SharpEventBus provides thread-safe asynchronous and synchronous event bus implementations, allowing you to easily publish and subscribe to events within your domain application.

Features

  • ✔️ Configurable Settings
  • ✔️ Event Publishing
  • ✔️ Event Subscribing
  • ✔️ Event Consumption
  • ✔️ Asynchronous & Syncronous Event Consuming

Notes

  • 🔄 Async mode automatically consumes events in the background.
  • ⚙️ Sync mode requires manual consumption via ConsumeEvents();

Planned Features

  • ❌ Event Triggers
  • ❌ Event Hooks Support
  • ❌ Event Chaining Support
  • ❌ Event Filtering
  • ❌ Event Priorities
  • ❌ Event Scheduler
  • ❌ Better Factory/Builder Support
  • ❌ User-Implemented Event Consumer Support

Syncronous Example

using SharpEventBus;
using SharpEventBus.Events;
using SharpEventBus.Subscribers;

// Manual Custom Configuration
var configuration = EventBusConfigurationBuilder.Create(builder =>
{
    builder.WithDebugLogging();
});

// Custom configuration
var eventBus = SyncEventBusBuilder.Create(options =>
{
    // With a manual builder
    options.WithConfiguration(configuration);

    // With a auto builder
    options.WithConfiguration(builder =>
    {
        builder.WithDebugLogging();
    });
});

// Create a default EventBus instance with all internal defaults
var eventBus = SyncEventBusBuilder.Create();

// Create a custom EventBus with options
var eventBus = SyncEventBusBuilder.Create(options =>
{
    // Add custom implementations, or dont and use for default
    options.WithEventQueueFactory(() => new CustomEventQueue());
    options.WithEventDispatcherFactory(() => new CustomEventDispatcher());
});

// Subscribe to events
eventBus.AddSubscriber(new OrderPlacedSubscriber());

// Publish an event to subscribers
eventBus.Publish(new OrderPlacedEvent("Order123", DateTime.UtcNow));

// Manually have to call ConsumeEvents to consume events
eventBus.ConsumeEvents();

// Event model definition
public record OrderPlacedEvent(string OrderId, DateTime Timestamp) : IEvent;

// Subscriber implementation
public sealed class OrderPlacedSubscriber : SubscriberBase<OrderPlacedEvent>
{
    public override void OnEvent(OrderPlacedEvent e)
    {
        Console.WriteLine($"Order placed: {e.OrderId} at {e.Timestamp}");
    }
}

## Asyncronous Example

```csharp
using SharpEventBus;
using SharpEventBus.Events;
using SharpEventBus.Subscribers;

// Manual Custom Configuration
var configuration = EventBusConfigurationBuilder.Create(builder =>
{
    builder.WithDebugLogging();
    builder.WithMaxConsumerConcurrency(16);
});

// Custom configuration
var asyncEventBus = AsyncEventBusBuilder.Create(builder =>
{
    // With a manual builder
    options.WithConfiguration(configuration);

    // With a auto builder
    options.WithConfiguration(builder =>
    {
        builder.WithDebugLogging();
        builder.WithMaxConsumerConcurrency(16);
    });
});

// Create a default EventBus instance with all internal defaults
var eventBus = SyncEventBusBuilder.Create();

// Create a custom EventBus with options
var eventBus = SyncEventBusBuilder.Create(options =>
{
    // Add custom implementations, or dont and use for default
    options.WithEventQueueFactory(() => new CustomEventQueue());
    options.WithEventDispatcherFactory(() => new CustomEventDispatcher());
});

// Subscribe to events
// Note - Will automatically start to Consume events related to subscriber once the subscriber is added
asyncEventBus.AddSubscriber(new OrderPlacedAsyncSubscriber());

// Publish an event to subscribers
asyncEventBus.Publish(new OrderPlacedEvent("Order123", DateTime.UtcNow));

// Event model definition
public record OrderPlacedEvent(string OrderId, DateTime Timestamp) : IEvent;

// Subscriber implementation
public sealed class OrderPlacedAsyncSubscriber : AsyncEventSubscriberBase<OrderPlacedEvent>
{
    public override async Task OnEventAsync(OrderPlacedEvent e)
    {
        // Simulated IO Work
        await Task.Delay(Random.Shared.Next(0, 50));

        Console.WriteLine($"Order placed: {e.OrderId} at {e.Timestamp}");
    }
}
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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
2.0.0 135 6/3/2025
1.0.0 144 5/29/2025