OrionKey 0.5.0
dotnet add package OrionKey --version 0.5.0
NuGet\Install-Package OrionKey -Version 0.5.0
<PackageReference Include="OrionKey" Version="0.5.0" />
<PackageVersion Include="OrionKey" Version="0.5.0" />
<PackageReference Include="OrionKey" />
paket add OrionKey --version 0.5.0
#r "nuget: OrionKey, 0.5.0"
#:package OrionKey@0.5.0
#addin nuget:?package=OrionKey&version=0.5.0
#tool nuget:?package=OrionKey&version=0.5.0
OrionKey
Source-generated strongly-typed IDs for .NET.
OrionKey turns a readonly partial struct into a fully-featured strongly-typed ID with a
single attribute. A bundled Roslyn source generator emits the equality, comparison, factory,
serialization, and persistence members, so a domain ID stops being a bare Guid or long
and becomes a distinct type the compiler can check. No base class, no runtime reflection,
nothing to wire up.
Quick start
dotnet add package OrionKey
Mark a partial struct with [OrionId] and a storage type. The optional second type
argument selects a generation strategy:
[OrionId<Guid>] public readonly partial struct OrderId;
[OrionId<long, Snowflake>] public readonly partial struct UserId;
[OrionId<string, Ulid>] public readonly partial struct TenantId;
[OrionId<string, NanoId>] public readonly partial struct SessionId;
Strategies
| Declaration | Storage | New() | Sortable |
|---|---|---|---|
[OrionId<Guid>] |
Guid | Guid.NewGuid() |
no |
[OrionId<Guid, GuidV7>] |
Guid | UUIDv7 | yes |
[OrionId<Guid, SequentialGuid>] |
Guid | SQL Server-ordered sequential GUID | yes |
[OrionId<long, Snowflake>] |
long | Snowflake | yes |
[OrionId<string, Ulid>] |
string | ULID | yes |
[OrionId<string, Ksuid>] |
string | KSUID | yes |
[OrionId<string, ObjectId>] |
string | MongoDB ObjectId (24-char hex) | yes |
[OrionId<string, NanoId>] |
string | NanoId | no |
[OrionId<string, Cuid2>] |
string | CUID2 | no |
[OrionId<int>] / [OrionId<long>] |
int/long | none (DB identity) | n/a |
The int and long integer forms have no New() factory; they model ids assigned
externally, typically by a database identity column.
What gets generated
For every annotated struct the generator emits, as partial companions:
- The struct body itself: a
Valuemember, aNew()factory (strategy-backed types), and value-basedIEquatableequality with==/!=. - An
IComparable/IComparable<T>implementation, emitted only for sortable strategies (GuidV7,SequentialGuid,Snowflake,Ulid,Ksuid,ObjectId). - A
System.Text.JsonJsonConverterso the id serializes as its underlying value. - A
TypeConverterfor framework conversions and ASP.NET Core model binding. IParsable<T>andISpanParsable<T>implementations for allocation-aware parsing.- An EF Core
ValueConverter, emitted only when the project references EF Core, so the id can be used directly as an entity key or property.
The generated converters are discovered automatically by System.Text.Json, EF Core, and
ASP.NET Core model binding. No manual registration is required.
Library integration
When the consumer project references Dapper, Newtonsoft.Json, MongoDB.Driver, or Swashbuckle.AspNetCore, OrionKey emits matching companions for every [OrionId] struct:
| Library | Generated companion | One-line registration |
|---|---|---|
| Dapper | <Id>DapperTypeHandler |
OrionKeyDapperRegistrar.Register(); |
| Newtonsoft.Json | <Id>NewtonsoftJsonConverter |
OrionKeyNewtonsoftJsonRegistrar.AddTo(settings); |
| MongoDB driver | <Id>BsonSerializer |
OrionKeyMongoRegistrar.Register(); |
| Swashbuckle (OpenAPI) | <Id>SchemaFilter |
OrionKeyOpenApiRegistrar.AddTo(options); |
OrionKey is released under the MIT License.
AOT & trimming
OrionKey 0.4+ is compatible with Native AOT and trimming. The runtime assembly carries <IsAotCompatible>true</IsAotCompatible> and a CI matrix publishes a self-contained AOT binary on linux-x64 and win-x64 every push.
Newtonsoft.Json, MongoDB.Driver, Swashbuckle.AspNetCore, and Dapper are not fully AOT-clean as of mid-2026 — prefer System.Text.Json, EF Core, and the BCL TypeConverter/IParsable pipelines in AOT projects. When using System.Text.Json source generation, register the generated <Id>JsonConverter instances into JsonSerializerOptions.Converters and pass the options into new JsonContext(options). For IParsable<T>, invoke T.Parse(text, null) via a where T : IParsable<T> constraint (the emitted Parse is an explicit interface implementation).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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 is compatible. 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 is compatible. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on OrionKey:
| Package | Downloads |
|---|---|
|
OrionKey.Testing
Deterministic ID generators for testing code that uses OrionKey strongly-typed IDs. |
GitHub repositories
This package is not used by any popular GitHub repositories.