EventFlux 1.1.9
See the version list below for details.
dotnet add package EventFlux --version 1.1.9
NuGet\Install-Package EventFlux -Version 1.1.9
<PackageReference Include="EventFlux" Version="1.1.9" />
<PackageVersion Include="EventFlux" Version="1.1.9" />
<PackageReference Include="EventFlux" />
paket add EventFlux --version 1.1.9
#r "nuget: EventFlux, 1.1.9"
#:package EventFlux@1.1.9
#addin nuget:?package=EventFlux&version=1.1.9
#tool nuget:?package=EventFlux&version=1.1.9
NuGet Package Information
EventFlux
EventFlux is a lightweight and performance-focused event processing library for .NET. It makes it easy to trigger a request and process it with multiple handlers, add pipeline behaviors, and perform deferred batch triggering.
Key Features
- Event-driven architecture
- Automatic event handler discovery and logging
- Support for deferred/batch event triggering
- Support for multiple handlers
- Add pipeline behaviors (e.g., validation, logging, cache)
- Dynamic dispatch
- Handler prerequisite query: Pre-evaluation with the
CanHandlemethod
Quick Start
- Install a package from NuGet (package name provided as an example):
dotnet add package EventFlux
- Add services in Program.cs / Startup.cs:
var builder = WebApplication.CreateBuilder(args);
// Basic plugins
builder.Services
.AddEventBus(AssemblyReference.Assemblies) // or any assembly list you want
.AddEventLogging() // optional
.AddEventTimeout(); // optional
builder.Services.AddEventDispatcher();
// Example: Adding custom pipeline behavior
builder.Services.AddTransient(typeof(IEventCustomPipeline<,>), typeof(ValidationBehavior<,>));
var app = builder.Build();
app.Run();
Usage examples
- EventBus (usage awaiting an event → a response):
public class ExampleController(IEventBus _eventBus) : ControllerBase
{
[HttpPost("create-user")]
public async Task<IActionResult> CreateUser([FromBody] CreateUserCommandRequest command)
{
CreateUserCommandResponse response = await _eventBus.SendAsync(command);
return Ok(response);
}
}
- EventDispatcher (for more dynamic/multiple redirect scenarios):
public class ExampleController(IEventDispatcher _eventDispatcher) : ControllerBase
{
[HttpPost("update-user")]
public async Task<IActionResult> UpdateUser([FromBody] UpdateUserCommandRequest command)
{
UpdateUserCommandResponse response = await _eventDispatcher.SendAsync(command);
return Ok(response);
}
}
Example custom pipeline
public class ValidationBehavior<TRequest, TResponse> : IEventCustomPipeline<TRequest, TResponse>
where TRequest : IEventRequest<TResponse>
where TResponse : IEventResponse
{
public async Task<TResponse> Handle(
TRequest request,
EventHandlerDelegate<TResponse> next,
CancellationToken cancellationToken)
{
Console.WriteLine($"Validating {typeof(TRequest).Name}");
return await next();
}
}
CanHandle example
You can use CanHandle to perform a precondition check before calling the handler:
public class ExampleEventHandler : IEventHandler<ExampleEventRequest, ExampleEventResponse>
{
public bool CanHandle(ExampleEventRequest @event)
=> @event.Num > 1000;
public async Task<ExampleEventResponse> Handle(ExampleEventRequest @event)
{
return new() { Res = @event.Num.ToString() };
}
}
Tests
- The project includes unit tests for EventBus and EventDispatcher. The tests verify the following:
- Correct operation of the SendAsync and PublishAsync methods
- Whether handlers are triggered according to the CanHandle method
- Correct execution of the pipeline (e.g., TimeoutBehavior, TriggerBehavior) and handler chain
- Appropriate handling of cancellation token and timeout conditions
- Correct catching or throwing of exceptions
cd .\test\EventFlux.Test\
dotnet test
Configuration and Tips
- AddEventLogging: Adds logging to monitor or debug the event flow.
- AddEventTimeout: Provides a timeout policy for long-running handlers.
- AddEventBus / AddEventDispatcher: Specify which assemblies to scan explicitly for handlers.
- EventBus: Basic event sending and publishing.
- EventDispatcher: Extends EventBus by allowing pipeline behaviors (
IEventCustomPipeline<,>,IEventCustomPipeline<>) to be added between the request and handlers.
- Pipeline Behaviors: Inject custom logic such as validation, logging, caching, or other pre/post-processing for handlers.
- CanHandle: Implement preconditions in handlers to control whether a handler should execute.
- Error Handling: Catch exceptions within handlers to log or generate appropriate responses; unhandled exceptions may propagate depending on your implementation.
- Unit Tests: Use mocks or isolated pipeline behaviors to test handler execution, timeouts, and cancellation tokens.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. 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 is compatible. 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 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 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. |
-
net6.0
-
net7.0
-
net8.0
-
net9.0
NuGet packages (2)
Showing the top 2 NuGet packages that depend on EventFlux:
| Package | Downloads |
|---|---|
|
EventFlux.RabbitFlow
Lightweight .NET library for event-driven applications, providing distributed event support and domain events with EventFlux and RabbitMQ. |
|
|
EventFlux.RedisFlow
Lightweight .NET library for event-driven applications, providing distributed event support and domain events with EventFlux and Redis. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release with event-based CQRS support.