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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Len.StronglyTypedId.Generators" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Len.StronglyTypedId.Generators" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="Len.StronglyTypedId.Generators" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Len.StronglyTypedId.Generators --version 1.3.0
                    
#r "nuget: Len.StronglyTypedId.Generators, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Len.StronglyTypedId.Generators@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Len.StronglyTypedId.Generators&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=Len.StronglyTypedId.Generators&version=1.3.0
                    
Install as a Cake Tool

StronglyTypedId

NuGet License: MIT

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) from ConfigureConventions, plus a model-scanning StronglyTypedIds.ApplyTo(modelBuilder) from OnModelCreating. Both overloads are generated together whenever a DbContext overrides ConfigureConventions and EF Core ≥ 7.0.0 is referenced.
  • Dapper — StronglyTypedIds.ApplyTo(connection) registers TypeHandlers.
  • Swashbuckle / OpenAPI — StronglyTypedIds.ApplyTo(options) for AddSwaggerGen / AddOpenApi.
  • ASP.NET Core MVC — StronglyTypedIds.ApplyTo(options) enables [FromRoute] OrderId id and {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

MIT License.

There are no supported framework assets in this package.

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