FlowR 10.0.1
dotnet add package FlowR --version 10.0.1
NuGet\Install-Package FlowR -Version 10.0.1
<PackageReference Include="FlowR" Version="10.0.1" />
<PackageVersion Include="FlowR" Version="10.0.1" />
<PackageReference Include="FlowR" />
paket add FlowR --version 10.0.1
#r "nuget: FlowR, 10.0.1"
#:package FlowR@10.0.1
#addin nuget:?package=FlowR&version=10.0.1
#tool nuget:?package=FlowR&version=10.0.1
FlowR
About FlowR
FlowR is an open-source continuation of the MediatR library, which will become commercial starting with version 13. This fork aims to maintain the simplicity and power of the original while ensuring it remains freely available to the community.
FlowR is an elegant and powerful mediator implementation for .NET with a focus on workflow automation. Unlike other frameworks, FlowR relies on clear communication patterns and seamlessly supports both simple and complex use cases.
The library enables:
- Clean separation of request and processing (CQRS pattern)
- Implementation of complex workflows through chained requests
- Easy extensibility through pipeline behaviors
- Support for synchronous and asynchronous code
- Full compatibility with legacy MediatR projects
Installation
FlowR can be easily installed via NuGet:
Install-Package FlowR
Or via the .NET Core command line:
dotnet add package FlowR
Using Only the Contracts
To use only the contract classes and interfaces (useful when you only need definitions in a separate assembly):
Install-Package FlowR.Contracts
This includes:
IRequest(including generic variants)INotificationIStreamRequest
Registration with IServiceCollection
FlowR supports direct integration with Microsoft.Extensions.DependencyInjection.Abstractions:
services.AddFlowR(cfg => cfg.RegisterServicesFromAssemblyContaining<Startup>());
Or with an assembly:
services.AddFlowR(cfg => cfg.RegisterServicesFromAssembly(typeof(Startup).Assembly));
Core Concepts
Requests
Requests are objects that represent a requirement and expect a response:
public record GetUserQuery(int UserId) : IRequest<UserDto>;
public class GetUserQueryHandler : IRequestHandler<GetUserQuery, UserDto>
{
public async Task<UserDto> Handle(GetUserQuery request, CancellationToken cancellationToken)
{
// Implementation to retrieve a user
}
}
Notifications
Notifications allow publishing events to multiple handlers:
public record UserCreatedNotification(int UserId, string Username) : INotification;
public class EmailNotificationHandler : INotificationHandler<UserCreatedNotification>
{
public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
{
// Send a welcome email
}
}
Pipeline Behavior
FlowR allows inserting custom behaviors into the request pipeline:
public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
// Log before processing
var response = await next();
// Log after processing
return response;
}
}
Compatibility with MediatR
FlowR provides full compatibility with MediatR through type forwarding and interface aliases. This enables seamless migration from existing MediatR projects to FlowR.
Performance Optimization with Source Generation
FlowR now offers an option for performance optimization through source generation. This avoids costly reflection and assembly scans at runtime by generating the code for handler registration during the build process.
Using Source Generation
To activate source generation, use the UseSourceGeneration() extension method in your configuration:
services.AddFlowR(config =>
{
config.RegisterServicesFromAssemblyContaining<Startup>()
.UseSourceGeneration(); // Activates source generation
});
How It Works
Instead of scanning all assemblies at runtime, which is resource-intensive, the FlowR Source Generator generates a static registration class at compile time. This contains all information about handlers, notifications, and other FlowR components that can then be registered directly without reflection.
- During the build, the source generator analyzes your code
- It detects all handlers, notifications, and other FlowR components
- It generates a special registration class that knows about these components
- At runtime, this generated class is used instead of assembly scanning
Benefits of Source Generation
- Significantly improved startup performance: No costly reflection and assembly scans at runtime
- Early error detection: Issues with handlers are detected at compile time
- Optimized handler registration: Direct registration of handlers without dynamic type searching
- Reduced memory usage: Fewer temporary objects during initialization
- Better scalability: The startup time doesn't grow with the number of handlers
When to Use Source Generation
Source generation is particularly useful for:
- Applications with many handlers and notifications
- Services where startup time is critical
- Serverless functions that need to start quickly
- Containerized applications where fast startup is important
For small applications or during development, traditional assembly scanning might be more practical since it doesn't require recompilation when new handlers are added.
License
FlowR is available under the Apache 2.0 license. See LICENSE for details. Hint: FlowR will stay free to use
| Product | Versions 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 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- FlowR.Contracts (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
-
net10.0
- FlowR.Contracts (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
-
net8.0
- FlowR.Contracts (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
-
net9.0
- FlowR.Contracts (>= 10.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.