Concordia.Generator
2.4.1
See the version list below for details.
dotnet add package Concordia.Generator --version 2.4.1
NuGet\Install-Package Concordia.Generator -Version 2.4.1
<PackageReference Include="Concordia.Generator" Version="2.4.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Concordia.Generator" Version="2.4.1" />
<PackageReference Include="Concordia.Generator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Concordia.Generator --version 2.4.1
#r "nuget: Concordia.Generator, 2.4.1"
#:package Concordia.Generator@2.4.1
#addin nuget:?package=Concordia.Generator&version=2.4.1
#tool nuget:?package=Concordia.Generator&version=2.4.1
Concordia.Generator: Compile-Time Handler Registration for Concordia
Concordia.Generator is the C# Source Generator component of the Concordia library. It automates the registration of your handlers at compile-time and generates a concrete GeneratedMediator class that dispatches requests and notifications with zero runtime overhead — no DI lookups, no reflection, no allocations on the hot path.
Table of Contents
- Why Concordia?
- Key Features
- Performance
- Installation
- Usage
- Contribution
- License
- NuGet Packages
- Contact
- Support
Why Concordia?
- An Open-Source Alternative: Concordia was created as an open-source alternative in response to other popular mediator libraries (like MediatR) transitioning to a paid licensing model. We believe core architectural patterns should remain freely accessible to the developer community.
- Lightweight and Minimal: Provides only the essential Mediator pattern functionalities, without unnecessary overhead.
- Optimized Performance: The Source Generator goes beyond simple handler registration — it produces a
GeneratedMediatorwith constructor-injected handler singletons and directis-type-switch dispatch, achieving ~1–2 ns per call with zero allocations on the hot path. - Easy DI Integration: Integrates seamlessly with
Microsoft.Extensions.DependencyInjection. - Same MediatR Interfaces: Uses interfaces with identical signatures to MediatR, making migration or parallel adoption extremely straightforward.
- CQRS and Pub/Sub Patterns: Facilitates the implementation of Command Query Responsibility Segregation (CQRS) and Publisher/Subscriber principles, enhancing separation of concern and code maintainability.
Key Features
- Two generated files:
ConcordiaGeneratedHandlersRegistrations.g.cs— aAddConcordiaHandlers()DI extension method that registers all discovered handlers as Singletons and wires upGeneratedMediatorasIMediator/ISender.ConcordiaGeneratedMediator.g.cs— a sealedGeneratedMediatorclass with constructor-injected handlers, direct type-switch dispatch, and anIsCompletedSuccessfullyfast-path for notifications.
- Zero Registration Friction: The
[assembly: DiscoverConcordiaHandlers]attribute is injected automatically via a.targetsfile — no manual setup required. - Cross-Assembly Discovery: Handlers defined in referenced assemblies that also use
Concordia.Generatorare discovered and included automatically. - Configurable Method Name: Rename the generated extension method via
<ConcordiaGeneratedMethodName>in your.csproj.
Performance
Benchmarks measured with BenchmarkDotNet on .NET 10, Intel Core i7-13800H. Ratio = relative to MediatR (1.00).
Send Command (fire-and-forget, no pipeline)
| Method | Mean | Ratio | Allocated |
|---|---|---|---|
| MediatR | 50.5 ns | 1.00 | 128 B |
| Concordia | 22.2 ns | 0.44 | 0 B |
| ConcordiaGen | 1.7 ns | 0.03 | 0 B |
| Martin | 5.8 ns | 0.11 | 0 B |
Publish Notification (2 handlers)
| Method | Mean | Ratio | Allocated |
|---|---|---|---|
| MediatR | 87.2 ns | 1.00 | 440 B |
| Concordia | 74.0 ns | 0.85 | 224 B |
| ConcordiaGen | 1.6 ns | 0.02 | 0 B |
| Martin | 7.9 ns | 0.09 | 0 B |
Installation
Install Concordia.Core and Concordia.Generator in your application project:
dotnet add package Concordia.Core --version 2.3.0
dotnet add package Concordia.Generator --version 2.3.0
Usage
Define your Handlers, Processors, and Behaviors (as described in
Concordia.Core's documentation).Configure your
.csproj: ReferenceConcordia.GeneratorasPrivateAssets="all"so it is consumed only as a Roslyn analyzer and not exposed as a transitive dependency. Optionally set a custom method name:<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <ConcordiaGeneratedMethodName>AddMyAppHandlers</ConcordiaGeneratedMethodName> </PropertyGroup> <ItemGroup> <CompilerVisibleProperty Include="ConcordiaGeneratedMethodName" /> </ItemGroup> <ItemGroup> <PackageReference Include="Concordia.Core" Version="2.3.0" /> <PackageReference Include="Concordia.Generator" Version="2.3.0" PrivateAssets="all" /> </ItemGroup> </Project>Register services in
Program.cs:A single call to
AddConcordiaHandlers()(or your custom name) registers everything — handler Singletons and theGeneratedMediatorwired asIMediator/ISender:using Concordia; var builder = WebApplication.CreateBuilder(args); // Registers all handlers + GeneratedMediator as IMediator/ISender in one call. builder.Services.AddConcordiaHandlers(); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run();Inject
IMediatororISenderin your controllers / services as usual:public class ProductsController : ControllerBase { private readonly ISender _sender; public ProductsController(ISender sender) => _sender = sender; [HttpGet("{id}")] public async Task<IActionResult> Get(int id) => Ok(await _sender.Send(new GetProductByIdQuery { ProductId = id })); }
The generator automatically finds your handler implementations and generates two files. Look for them under Dependencies → Analyzers → Concordia.Generator in Solution Explorer.
Contribution
Feel free to contribute to the project! Report bugs, suggest new features, or submit pull requests. Please follow the Contributing Guidelines.
License
This project is released under the MIT License. See the LICENSE file for more information.
NuGet Packages
- Concordia.Core
- Concordia.Generator (for compile-time handler registration)
- Concordia.MediatR (for MediatR compatibility)
Contact
For any questions, issues, or feedback, please open an issue on the GitHub repository.
Support
If you find this library useful, consider supporting its development: Buy Me a Coffee.
| 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 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. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.5.0 | 128 | 4/12/2026 |
| 2.4.1 | 90 | 4/8/2026 |
| 2.3.3 | 449 | 2/2/2026 |
| 2.3.2 | 109 | 2/2/2026 |
| 2.3.1 | 121 | 2/1/2026 |
| 2.3.0 | 116 | 2/1/2026 |
| 2.2.0 | 109 | 2/1/2026 |
| 2.0.0 | 193 | 1/11/2026 |
| 1.3.0 | 1,127 | 11/10/2025 |
| 1.2.6 | 230 | 10/6/2025 |
| 1.2.5 | 15,917 | 9/4/2025 |
| 1.2.3 | 215 | 9/4/2025 |
| 1.2.2 | 224 | 9/3/2025 |
| 1.2.0 | 260 | 8/31/2025 |
| 1.1.0 | 235 | 8/30/2025 |
| 1.0.1 | 189 | 7/30/2025 |
| 1.0.0 | 157 | 7/30/2025 |