Concordia.Generator
1.0.1
dotnet add package Concordia.Generator --version 1.0.1
NuGet\Install-Package Concordia.Generator -Version 1.0.1
<PackageReference Include="Concordia.Generator" Version="1.0.1" />
<PackageVersion Include="Concordia.Generator" Version="1.0.1" />
<PackageReference Include="Concordia.Generator" />
paket add Concordia.Generator --version 1.0.1
#r "nuget: Concordia.Generator, 1.0.1"
#:package Concordia.Generator@1.0.1
#addin nuget:?package=Concordia.Generator&version=1.0.1
#tool nuget:?package=Concordia.Generator&version=1.0.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 request handlers, notification handlers, pre-processors, post-processors, and pipeline behaviors at compile-time, eliminating the need for runtime reflection and significantly improving application startup performance.
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: Thanks to Source Generators, handler discovery and registration happen entirely at compile-time, ensuring faster application startup and zero runtime reflection.
- 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
- Automatic Handler Registration: Scans your assemblies at compile-time to find and register
IRequestHandler
,INotificationHandler
,IPipelineBehavior
,IRequestPreProcessor
, andIRequestPostProcessor
implementations. - Zero Runtime Reflection: All service registration code is generated as C# source files, which are then compiled directly into your assembly.
- Configurable Namespace and Method Names: Control the generated class's namespace and the DI extension method's name via MSBuild properties in your
.csproj
file.
Installation
Install Concordia.Core and Concordia.Generator in your application project:
dotnet add package Concordia.Core --version 1.0.0
dotnet add package Concordia.Generator --version 1.0.0
Usage
Define your Handlers, Processors, and Behaviors (as described in
Concordia.Core
's documentation).Configure your
.csproj
: Add theConcordia.Generator
as aProjectReference
with specific attributes and optionally configure the generated method name and namespace.<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <ConcordiaGeneratedMethodName>AddMyCustomMediatorHandlers</ConcordiaGeneratedMethodName> </PropertyGroup> <ItemGroup> <ProjectReference Include="PathToYour\Concordia.Core\Concordia.Core.csproj" /> <ProjectReference Include="PathToYour\Concordia.Generator\Concordia.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> </ItemGroup> </Project>
Register services in
Program.cs
:using Concordia; // Required for IMediator, ISender using Concordia.DependencyInjection; // For AddConcordiaCoreServices using MyProject.Web; // Example: Namespace where ConcordiaGeneratedRegistrations is generated var builder = WebApplication.CreateBuilder(args); // 1. Register Concordia's core services. builder.Services.AddConcordiaCoreServices(); // 2. Register your specific handlers and pipeline behaviors discovered by the generator. // The method name will depend on your .csproj configuration (e.g., AddMyCustomMediatorHandlers). builder.Services.AddMyCustomMediatorHandlers(); // Use the name configured in .csproj builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run();
The Source Generator will automatically find your handler implementations and generate a static class (e.g., ConcordiaGeneratedRegistrations
) containing an extension method (e.g., AddMyCustomMediatorHandlers
) that registers all your services with the DI container.
Contribution
Feel free to contribute to the project! Report bugs, suggest new features, or submit pull requests.
License
This project is released under the [Insert your license here, e.g., MIT License].
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
- Concordia.Core (>= 1.0.1)
- Microsoft.CodeAnalysis.CSharp (>= 4.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.