RxEventbus.Core 1.0.14

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

English | chinese

RxEventbus

A lightweight System.Reactive EventBus designed to help .NET applications achieve low coupling, asynchronous communication, and high extensibility between modules.

πŸš€ Core Features

  • Lightweight and Efficient: Built upon Reactive Extensions for .NET (System.Reactive .net ), providing an efficient and simple event publishing and subscription mechanism.
  • Module Decoupling: Achieves indirect communication between modules through an event-driven architecture, effectively reducing code coupling.
  • Asynchronous Event Handling: Supports asynchronous event handlers, ensuring event processing does not block the main thread.
  • Automatic Registration and Subscription: Automatically discovers and registers all event handlers, subscribing them upon application startup.
  • Global Error Handling: Provides a default global event error handling mechanism, which can be overridden as needed.

πŸ’‘ How to Use

1. Installation

Install the NuGet package in your .NET project using the NuGet Package Manager Console:

dotnet add package RxEventbus.Core

πŸ“¦ Find more details about the NuGet package here: RxEventbus.Core on NuGet.org

2. Service Registration

In your Program.cs or Startup.cs file, simply call the AddEventBus() extension method to register the EventBus and all event handlers.

// Program.cs
public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        builder.Services.AddEventBus(); // Register EventBus and Handlers
    }
}

3. Defining Events

Define an event type object for your event. This is a simple C# record example, recommended to be defined within your application's domain models or a designated events directory.

// Example Event Payload
public record StockInEvent(int ProductId, int Quantity, string Location);

4. Publishing Events

Obtain an IAppEventBus instance via dependency injection, then call its Publish method, passing an AppEvent<T> object where T is your event's payload type.

using HaiyuEBR.Service.RxEventbus.Events; // Ensure this using directive is present

// Assume StockInEvent record is defined elsewhere, e.g., in a shared library or domain model
// public record StockInEvent(int ProductId, int Quantity, string Location);

public class OrderService
{
    private readonly IAppEventBus _eventBus;

    public OrderService(IAppEventBus eventBus)
    {
        _eventBus = eventBus;
    }

    public void ProcessOrder(int productId, int quantity, string location)
    {
        // Create an AppEvent object with your specific payload
        var stockInPayload = new StockInEvent(productId, quantity, location);
        var stockInAppEvent = new AppEvent<StockInEvent>(stockInPayload);

        _eventBus.Publish(stockInAppEvent);
        Console.WriteLine($"Published Stock In Event: Product ID={stockInAppEvent.Payload.ProductId}");
    }
}

5. Handling Events

To handle an event, simply create a class that implements the IAppEventHandler<T> interface, where T is the type of your event's payload. This handler will be automatically discovered and registered upon application startup.

using HaiyuEBR.Service.RxEventbus; // Ensure this using directive is present
using HaiyuEBR.Service.RxEventbus.Events; // Ensure this using directive is present
using System.Threading.Tasks;

// Assume StockInEvent record is defined elsewhere
// public record StockInEvent(int ProductId, int Quantity, string Location);

public class TestStockInEventHandler : IAppEventHandler<StockInEvent>
{
    public Task HandleAsync(AppEvent<StockInEvent> evt)
    {
        Console.WriteLine($"[TestStockInEventHandler] Handling Stock In Event: Product ID={evt.Payload.ProductId}, Quantity={evt.Payload.Quantity}, Location={evt.Payload.Location}");
        return Task.CompletedTask;
    }

    // Optional: Override OnEventHandledAsync, OnErrorAsync, OnCompletedAsync for specific behavior
    public Task OnEventHandledAsync(AppEvent<StockInEvent> evt)
    {
        Console.WriteLine($"[TestStockInEventHandler] Finished handling Stock In Event for Product ID: {evt.Payload.ProductId}");
        return Task.CompletedTask;
    }
}

πŸ› Console Output

Published Stock In Event: Product ID=101
[TestStockInEventHandler] Handling Stock In Event: Product ID=101, Quantity=50, Location=δ»“εΊ“A
[TestStockInEventHandler] Finished handling Stock In Event for Product ID: 101

🌐 Asynchronous & Concurrency Considerations

  • Default Asynchronous Processing: The HandleAsync method of IAppEventHandler<T> returns a Task, ensuring that event processing is non-blocking.
  • Concurrency Control: For time-consuming or CPU-intensive operations within event handlers, to prevent blocking the event publishing thread, you can add .ObserveOn(System.Reactive.Concurrency.Scheduler.Default) within the event bus's internal subscription chain. This offloads event processing to the thread pool for improved concurrency.

πŸ“‹ Future Improvements (Roadmap)

  • Simplified event type configuration, filtering event types based on the event object itself, enhancing extensibility. (Completed)

🀝 Contributing

We welcome and appreciate your contributions! If you have any questions, suggestions, or find a bug, please feel free to submit an Issue or a Pull Request on GitHub.

πŸ“œ License

This project is released under the MIT License.


Β© 2025 Godaday. All rights reserved.

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.

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
1.0.14 350 6/12/2025
1.0.13 311 6/10/2025
1.0.12 265 6/9/2025
1.0.11 255 6/9/2025
1.0.10 248 6/9/2025
1.0.9 242 6/9/2025
1.0.8 123 6/7/2025
1.0.6 131 6/7/2025
1.0.0 118 6/7/2025