Len.StronglyTypedId.Generators
1.3.0
dotnet add package Len.StronglyTypedId.Generators --version 1.3.0
NuGet\Install-Package Len.StronglyTypedId.Generators -Version 1.3.0
<PackageReference Include="Len.StronglyTypedId.Generators" Version="1.3.0" />
<PackageVersion Include="Len.StronglyTypedId.Generators" Version="1.3.0" />
<PackageReference Include="Len.StronglyTypedId.Generators" />
paket add Len.StronglyTypedId.Generators --version 1.3.0
#r "nuget: Len.StronglyTypedId.Generators, 1.3.0"
#:package Len.StronglyTypedId.Generators@1.3.0
#addin nuget:?package=Len.StronglyTypedId.Generators&version=1.3.0
#tool nuget:?package=Len.StronglyTypedId.Generators&version=1.3.0
StronglyTypedId
Len.StronglyTypedId is a Roslyn source generator (with analyzer + code fixes) that turns a one-line
record declaration into a fully featured strongly typed identifier. It generates the
IStronglyTypedId<TSelf, TPrimitiveId> and IParsable<TSelf> implementation plus System.Text.Json /
Newtonsoft.Json / EF Core / Dapper / Swashbuckle / ASP.NET Core integrations — so a Guid can never be
passed where an OrderId is expected, and vice versa.
Install
dotnet add package Len.StronglyTypedId
One package is enough — it already depends on Len.StronglyTypedId.Generators. Requires .NET 8.0+ SDK
and a target framework net8.0 / net10.0. Integrations are generated only when the matching package
is referenced.
Quick start
[StronglyTypedId]
public partial record struct OrderId(Guid Value);
var id = OrderId.Create(Guid.NewGuid()); // static factory
var parsed = OrderId.Parse("...", null); // IParsable<TSelf>
OrderId.TryParse("...", null, out var alsoParsed); // false instead of throwing
Supported primitive types: Guid, string, byte, sbyte, short, ushort, int, uint,
long, ulong, decimal, DateTime, DateTimeOffset, TimeSpan, and any enum. Use
record struct for a value type, record for a reference type.
String-backed ids are interned: equal string values share a single underlying instance, so a
repeated id costs almost no extra memory. Interning is scoped per id type (not the global
string.Intern pool), so it cannot leak memory for unbounded value sets.
Point Validator at a static method to reject invalid values:
[StronglyTypedId(Validator = nameof(Validate))]
public partial record struct OrderId(Guid Value)
{
private static bool Validate(Guid value) => value != Guid.Empty;
}
Integrations
All opt-in, generated only when the matching package is referenced:
- Serialization — System.Text.Json and Newtonsoft.Json converters via a generated
[JsonConverter]. - EF Core —
StronglyTypedIds.ApplyTo(configurationBuilder)fromConfigureConventions, plus a model-scanningStronglyTypedIds.ApplyTo(modelBuilder)fromOnModelCreating. Both overloads are generated together whenever aDbContextoverridesConfigureConventionsand EF Core ≥ 7.0.0 is referenced. - Dapper —
StronglyTypedIds.ApplyTo(connection)registersTypeHandlers. - Swashbuckle / OpenAPI —
StronglyTypedIds.ApplyTo(options)forAddSwaggerGen/AddOpenApi. - ASP.NET Core MVC —
StronglyTypedIds.ApplyTo(options)enables[FromRoute] OrderId idand{id:OrderId}.
Native AOT & trimming
The runtime library is marked <IsAotCompatible>true</IsAotCompatible>: the core types and every
generated converter avoid dynamic code generation and loading types by name, so strongly typed ids
work in Native AOT and trimmed applications. The only reflection entry point,
StronglyTypedIdExtensions.TryGetPrimitiveIdType / GetPrimitiveIdType / IsStronglyTypedId,
is annotated with [DynamicallyAccessedMembers(Interfaces)] so the interface metadata that identifies
a strongly typed id is preserved under trimming.
License
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Len.StronglyTypedId.Generators:
| Package | Downloads |
|---|---|
|
Len.StronglyTypedId
A source generator, analyzer, and code fix provider that turns a one-line record declaration into a fully featured strongly typed id, with built-in System.Text.Json, Newtonsoft.Json, Entity Framework Core, Dapper, Swashbuckle, and ASP.NET Core OpenAPI integrations. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.0 | 111 | 10/7/2026 |
| 1.3.0-preview.11 | 60 | 10/2/2026 |
| 1.3.0-preview.10 | 65 | 10/2/2026 |
| 1.3.0-preview.9 | 57 | 10/2/2026 |
| 1.3.0-preview.8 | 63 | 10/2/2026 |
| 1.3.0-preview.7 | 80 | 9/20/2026 |
| 1.3.0-preview.6 | 78 | 9/20/2026 |
| 1.3.0-preview.5 | 123 | 9/13/2026 |
| 1.3.0-preview.4 | 72 | 9/13/2026 |
| 1.2.1 | 2,313 | 2/26/2024 |
| 1.2.0 | 1,350 | 11/27/2023 |
| 1.1.3 | 1,512 | 10/8/2023 |
| 1.1.2 | 1,557 | 10/8/2023 |
| 1.1.1 | 1,815 | 5/20/2023 |
| 1.1.0 | 1,895 | 5/18/2023 |