ModulusKit.Generators
4.0.0
dotnet add package ModulusKit.Generators --version 4.0.0
NuGet\Install-Package ModulusKit.Generators -Version 4.0.0
<PackageReference Include="ModulusKit.Generators" Version="4.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ModulusKit.Generators" Version="4.0.0" />
<PackageReference Include="ModulusKit.Generators"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ModulusKit.Generators --version 4.0.0
#r "nuget: ModulusKit.Generators, 4.0.0"
#:package ModulusKit.Generators@4.0.0
#addin nuget:?package=ModulusKit.Generators&version=4.0.0
#tool nuget:?package=ModulusKit.Generators&version=4.0.0
ModulusKit.Generators
Roslyn incremental source generators for Modulus -- strongly typed IDs, handler registration, and module auto-discovery.
Installation
dotnet add package ModulusKit.Generators
Or as an analyzer reference in your .csproj:
<PackageReference Include="ModulusKit.Generators"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
Note: This is a development-dependency (analyzer) package -- it does not flow transitively through other
ModulusKit.*packages or through project references. Add the reference above to every project that defines handlers, validators, or[StronglyTypedId]types (and to the host, for module discovery). Solutions scaffolded by themodulusCLI have this wired up already.
Strongly Typed IDs
Generate type-safe entity identifiers with EF Core, JSON (including dictionary-key support), route/query binding, and comparison support:
using Modulus.Mediator.Abstractions;
[StronglyTypedId]
public readonly partial record struct OrderId;
[StronglyTypedId(typeof(int))]
public readonly partial record struct SequenceNumber;
[StronglyTypedId(typeof(string))]
public readonly partial record struct TenantId;
The generator produces: Value property, constructor, New() factory (Guid only), Empty, IComparable<T>, IParsable<T>/Parse/TryParse (minimal API route/query parameter binding), plus ValueConverter (EF Core), JsonConverter (System.Text.Json — including ReadAsPropertyName/WriteAsPropertyName for use as a Dictionary<TId, TValue> key), and TypeConverter (MVC model binding).
Supported backing types: Guid (default), int, long, string.
Bulk EF Core registration
When the compilation references EF Core, the generator also emits ModulusStronglyTypedIdConventions.UseModulusStronglyTypedIds(this ModelConfigurationBuilder) — one call from DbContext.ConfigureConventions that registers every discovered ID's ValueConverter (local declarations plus public ones from referenced assemblies that were themselves built with an EF Core reference):
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
=> configurationBuilder.UseModulusStronglyTypedIds();
Handler Registration
Auto-register all handlers and validators at compile time:
// Source-generated extension method
services.AddModulusHandlers();
Discovers: ICommandHandler<>, IQueryHandler<>, IStreamQueryHandler<>, IDomainEventHandler<>, IIntegrationEventHandler<>, and AbstractValidator<>.
Module Auto-Discovery
Auto-discover all IModuleRegistration implementations from referenced assemblies:
// Source-generated extension methods
builder.Services.AddAllModules(builder.Configuration);
app.MapAllModuleEndpoints();
Control initialization order with [ModuleOrder(n)].
Diagnostics
| ID | Severity | Description |
|---|---|---|
| MODGEN001 | Error | [StronglyTypedId] target must be partial |
| MODGEN002 | Error | [StronglyTypedId] target must be a record struct |
| MODGEN003 | Info | Open generic handler skipped for registration |
| MODGEN004 | Warning | IModuleRegistration missing required static methods |
| MODGEN005 | Error | [StronglyTypedId] backing type is unsupported (only Guid, int, long, string) |
| MODGEN006 | Error | [StronglyTypedId] target must be a top-level type |
Learn More
See the Modulus documentation for full generator reference.
Learn more about Target Frameworks and .NET Standard.
-
.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 |
|---|---|---|
| 4.0.0 | 102 | 7/26/2026 |
| 3.1.0 | 294 | 7/26/2026 |
| 3.0.0 | 231 | 7/26/2026 |
| 2.1.0 | 101 | 7/4/2026 |
| 2.0.0 | 106 | 7/3/2026 |
| 1.2.5 | 130 | 3/15/2026 |
| 1.2.4 | 116 | 3/15/2026 |
| 1.2.3 | 115 | 3/14/2026 |
| 1.2.2 | 114 | 3/14/2026 |
| 1.2.1 | 114 | 3/14/2026 |
| 1.2.0 | 123 | 3/14/2026 |
| 1.1.1 | 110 | 3/8/2026 |
| 1.1.0 | 111 | 3/5/2026 |
| 1.0.1 | 114 | 3/5/2026 |