A lightweight and extensible library for managing data flow and events in .NET applications, inspired by MediatR. Ideal for CQRS-based architectures, promoting separation of concerns and enhancing maintainability and scalability.
| Package | Version | Popularity |
|---|---|---|
NexumPack.Fluxor |
If you find this project helpful, consider giving it a ⭐ on GitHub to support the development.
- ✅ Lightweight and modular
- ✅ Supports command, event, and query handlers
- ✅ DI-ready with automatic registration
- ✅ Clear separation of concerns
- ✅ Based on
Microsoft.Extensions.DependencyInjection
Via .NET CLI:
dotnet add package NexumPack.FluxorTo reference only the contracts for Fluxor, which includes:
IRequest(including generic variants)- Represents a command or query that expects a single response
INotification- Represents an event broadcast to multiple handlers (if any)
This example demonstrates how to combine a Request (command/query) and a Notification (event) in a real-world use case.
✅ This scenario uses only
Microsoft.Extensions.DependencyInjection.Abstractionsfor DI registration — no framework-specific packages.
public class CreateCustomerCommand : IRequest<string>
{
public string Name { get; set; }
}
public class CustomerCreatedEvent : INotification
{
public Guid CustomerId { get; }
public CustomerCreatedEvent(Guid customerId)
{
CustomerId = customerId;
}
}public class CreateCustomerHandler : IRequestHandler<CreateCustomerCommand, string>
{
private readonly IMediator _mediator;
public CreateCustomerHandler(IMediator mediator)
{
_mediator = mediator;
}
public async Task<string> Handle(CreateCustomerCommand request, CancellationToken cancellationToken)
{
var id = Guid.NewGuid();
// Simulate persistence...
// Publish event
await _mediator.Publish(new CustomerCreatedEvent(id), cancellationToken);
return $"Customer '{request.Name}' created with ID {id}";
}
}
public class SendWelcomeEmailHandler : INotificationHandler<CustomerCreatedEvent>
{
public Task Handle(CustomerCreatedEvent notification, CancellationToken cancellationToken)
{
Console.WriteLine($"Sending welcome email to customer {notification.CustomerId}");
return Task.CompletedTask;
}
}You can register everything manually if you want full control:
services.AddSingleton<IMediator, Mediator>();
services.AddTransient<IRequestHandler<CreateCustomerCommand, string>, CreateCustomerHandler>();
services.AddTransient<INotificationHandler<CustomerCreatedEvent>, SendWelcomeEmailHandler>();Or use assembly scanning with:
services.AddFluxor();public class CustomerAppService
{
private readonly IMediator _mediator;
public CustomerAppService(IMediator mediator)
{
_mediator = mediator;
}
public async Task<string> CreateCustomer(string name)
{
return await _mediator.Send(new CreateCustomerCommand { Name = name });
}
}When the CreateCustomer method is called:
CreateCustomerHandlerhandles the request- It creates and persists the customer (simulated)
- It publishes a
CustomerCreatedEvent SendWelcomeEmailHandlerhandles the event
This structure cleanly separates commands (which change state and return a result) from notifications (which communicate to the rest of the system that something happened).
- Lightweight: Minimal dependencies and straightforward setup.
- In-Process Messaging: Facilitates in-process communication between components.
- Handler Registration: Automatically registers handlers from specified assemblies.
NexumPack.Fluxor targets .NET Standard 2.1, and is compatible with .NET Core 3.1+, .NET 5+, .NET 6+, .NET 7+, .NET 8, NET 9 and newer versions of the .NET runtime.
NexumPack.Fluxor was developed by Lucas Eduardo under the MIT license.