Zonit.Services.EventMessage 0.1.10

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

Event Message Service

Overview

Event Message Service is a powerful .NET library that enables event-driven architecture for .NET 8/9 applications. It allows seamless, decoupled communication between application components via events, resulting in maintainable and flexible codebases.


📦 NuGet Packages

Abstractions

Install-Package Zonit.Services.EventMessage.Abstractions 

NuGet Version NuGet Downloads

SQL Server Implementation

Install-Package Zonit.Services.EventMessage.SqlServer

NuGet Version NuGet Downloads


Features

  • Event Publishing & Subscription: Publish and subscribe to events with configurable concurrency control.
  • Transaction Support: Group events into transactions to be processed sequentially.
  • Task Management: Handle long-running tasks with status tracking and monitoring.
  • Automatic Handler Discovery: Automatically discover and register event handlers.
  • Concurrent Processing: Control the number of concurrently executed event handlers.
  • Timeout Handling: Configure timeouts for event processing.

Requirements

  • .NET 8 or .NET 9

Installation

Add the Event Message Service to your application using the service collection extension:

services.AddEventMessageService();

Usage

1. Creating Event Handlers

Implement event handlers by inheriting from EventBase<T>, where T is your event model type:

internal class Test1Event(ILogger<Test1Event> _logger) : EventBase<Test1Model>
{
    protected override async Task HandleAsync(Test1Model payload, CancellationToken cancellationToken)
    {
        await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
        _logger.LogInformation("[TestEvent] Number: {number} Title: {title}", 1, payload);
    }
}

2. Publishing Events

Publish events using the IEventProvider interface:

var eventProvider = serviceProvider.GetRequiredService<IEventProvider>();
eventProvider.Publish(new Test1Model { Title = "Test" });

3. Using Transactions

Group events to be processed sequentially within a transaction:

using (var transaction = eventProvider.Transaction())
{
    eventProvider.Publish(new Test1Model { Title = "Test1" });
    eventProvider.Publish(new Test2Model { Title = "Test2" });
    // Events are queued until the transaction is completed
}
// Events are processed after the transaction is disposed

4. Awaiting Transaction Completion

Wait for all events in a transaction to be processed:

using (var transaction = eventProvider.Transaction())
{
    eventProvider.Publish(new Test1Model { Title = "Test" });

    // Wait for all events to be processed
    await transaction.WaitForCompletionAsync();
}

Task Management System

The Event Message Service includes a comprehensive task management system for handling long-running operations with status tracking and monitoring.

1. Creating Task Handlers

Implement task handlers by inheriting from TaskBase<T>, where T is your task model:

internal class TestTask(ILogger<TestTask> _logger) : TaskBase<TestTaskModel>
{
    protected override async Task HandleAsync(TestTaskModel payload, CancellationToken cancellationToken)
    {
        await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
        _logger.LogInformation("[TestTask] Title: {title}", payload.Title);
    }
}

2. Publishing Tasks

Submit tasks to the queue using the ITaskProvider interface:

var taskProvider = serviceProvider.GetRequiredService<ITaskProvider>();
taskProvider.Publish(new TestTaskModel { Title = "Test Task" });

3. Monitoring Task Status

Subscribe to task status change events:

taskProvider.TaskStatusChanged += (sender, args) =>
{
    _logger.LogInformation("Task {taskId} status changed to {status}", args.TaskId, args.Status);
};

4. Viewing Active Tasks

Retrieve and display the list of active tasks:

var activeTasks = taskProvider.GetActiveTasks();
foreach (var task in activeTasks)
{
    _logger.LogInformation("Active Task: {taskId} - {status}", task.Id, task.Status);
}

5. Task Lifecycle Management

Tasks go through various states during their lifecycle:

  • Pending: Task is queued but not yet started.
  • Processing: Task is currently being processed.
  • Completed: Task finished successfully.
  • Failed: Task failed during processing.
  • Cancelled: Task was cancelled before completion.

Example Use Cases

  • Decoupling logic between independent application components
  • Implementing event-driven workflows
  • Handling system notifications and real-time updates
  • Creating robust background job queues

Contributing & Support

Found a bug or have a feature request? Open an issue on GitHub!


License

MIT

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 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 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on Zonit.Services.EventMessage:

Package Downloads
Zonit.Services.Dashboard

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.10 151 5/20/2025
0.1.9 228 5/11/2025
0.1.8 191 5/11/2025
0.1.7 125 2/19/2025
0.1.6 123 2/19/2025
0.1.5 114 2/19/2025
0.1.4 119 2/19/2025
0.1.3 111 2/19/2025
0.1.2 117 2/18/2025
0.1.1 114 2/18/2025
0.1.0 111 2/17/2025