Potapich.EventFlowChannel 1.2.0

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

Tests Coverage License NuGet

Event Dispatcher Architecture with Channel-Based Processing

Overview

A high-performance event-driven processing system built on .NET Standard 2.0 that provides thread-safe message dispatching with configurable channel options. The architecture combines the flexibility of event-driven programming with the robustness of channel-based communication patterns.

Key Features

  • Thread-Safe Event Dispatching - Safe concurrent event publishing and consumption
  • Configurable Channel Types - Support for both bounded and unbounded channels
  • Fluent Configuration API - Intuitive builder pattern for channel configuration
  • Multiple Reader Support - Configurable number of concurrent consumers
  • .NET Standard 2.0 Compatibility - Works with .NET Framework 4.6.1+ and .NET Core 2.0+
  • Dependency Injection Ready - Seamless integration with Microsoft DI container

Thread Safety

  • Thread-Safe Publishing - Multiple writers supported through channel synchronization
  • Concurrent Consumption - Multiple readers process events simultaneously
  • Lifecycle Management - Atomic start/stop operations with proper cancellation support
  • Exception Handling - Isolated error handling per event with continuous processing

Best Practices

  • Handler Design
  • Keep handlers focused and single-purpose
  • Implement proper error handling
  • Use async operations for I/O-bound work

Channel Configuration

  • Use bounded channels for predictable memory usage
  • Match reader count to available cores for CPU-bound work
  • Enable multiple writers for high-throughput scenarios

Monitoring

  • Implement comprehensive logging

Performance Considerations

  • Bounded Channels - Prevent memory overgrowth with configurable capacity
  • Reader Count - Optimize based on workload (I/O vs CPU bound)
  • Channel Options - SingleWriter/SingleReader optimizations available
  • Async/Await - Non-blocking operations throughout the pipeline

Example Use Cases

  • Microservices Communication - Event-based service coordination
  • Data Processing Pipelines - Parallel event processing
  • Real-time Applications - WebSocket/gRpc message processing
  • Background Processing - Async task execution

Core Components

Event Interfaces

Channel Infrastructure

Builder Pattern

Installation

<PackageReference Include="Potapich.EventFlowChannel" Version="1.0.1" />

Quick Start

1. Define Events and Handlers

public enum EventType { UserCreated, OrderProcessed }

public class UserCreatedEvent : IGenericEvent<EventType>
{
    public EventType EventType => EventType.UserCreated;
    public string UserName { get; set; }
}

public class UserEventHandler : IGenericEventHandler<EventType>
{
    public EventType EventType => EventType.UserCreated;
    
    public async Task HandleAsync(IGenericEvent<EventType> @event, CancellationToken token)
    {
        var userEvent = (UserCreatedEvent)@event;
        // Process event
    }
}

2. Configure Services

services.AddEventChannelBuilder<EventType>(typeof(Startup).Assembly)
        .AddSingleton<IGenericEventDispatcherLogger, MyLogger>();

3. Create and Use Channel

var channel = provider.GetService<IChannelBuilder<EventType>>()
    .Bounded()
    .WithCapacity(1000)
    .WithReadersCount(4)
    .WithMultipleWriters()
    .Build();

channel.Start();

await channel.Enqueue(new UserCreatedEvent { UserName = "John" });

Advanced Configuration

Bounded Channel with Custom Options

var channel = builder.Bounded()
    .WithCapacity(5000)
    .WithReadersCount(8)
    .WithFullMode(BoundedChannelFullMode.DropWrite)
    .WithMultipleWriters(false)
    .Build();

channel.Start();

await channel.Enqueue(new UserCreatedEvent { UserName = "John" });

Unbounded Channel

var channel = builder.Unbounded()
    .WithReadersCount(2)
    .WithMultipleWriters(true)
    .Build();

channel.Start();

await channel.Enqueue(new UserCreatedEvent { UserName = "John" });

Logging Integration

Microsoft.Extensions.Logging

public class MicrosoftLoggerAdapter : IGenericEventDispatcherLogger
{
    private readonly ILogger _logger;

    public MicrosoftLoggerAdapter(ILoggerFactory factory)
    {
        _logger = factory.CreateLogger("EventDispatcher");
    }

    public void LogWarning(string message) => _logger.LogWarning(message);
    public void LogError(string message) => _logger.LogError(message);
    public void LogError(string message, Exception ex) => _logger.LogError(ex, message);
}

Serilog

public class SerilogAdapter : IGenericEventDispatcherLogger
{
    public void LogWarning(string message) => Serilog.Log.Warning(message);
    public void LogError(string message) => Serilog.Log.Error(message);
    public void LogError(string message, Exception ex) => Serilog.Log.Error(ex, message);
}

Use IEventDispatcher without queue

Starting with version 1.1.0, the ability to explicitly register an event handler without registering a message channel has been added.

using ChannelReader;

services.AddEventDispatcher<EventType>(typeof(Startup).Assembly)
        .AddSingleton<IGenericEventDispatcherLogger, MyLogger>();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 Potapich.EventFlowChannel:

Package Downloads
Potapich.OpcUaNetStandart

High-performance event-driven processing system with channel-based architecture.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0 272 11/12/2025
1.1.0 172 10/23/2025
1.0.1 347 9/9/2025