StrongTypedId 2.2.1
See the version list below for details.
dotnet add package StrongTypedId --version 2.2.1
NuGet\Install-Package StrongTypedId -Version 2.2.1
<PackageReference Include="StrongTypedId" Version="2.2.1" />
<PackageVersion Include="StrongTypedId" Version="2.2.1" />
<PackageReference Include="StrongTypedId" />
paket add StrongTypedId --version 2.2.1
#r "nuget: StrongTypedId, 2.2.1"
#:package StrongTypedId@2.2.1
#addin nuget:?package=StrongTypedId&version=2.2.1
#tool nuget:?package=StrongTypedId&version=2.2.1
StrongTypedId
A super small library for providing strong typed Ids (as opposed to using primitives).
The benefit of this is simple: You don't run the risk of accidentally using the wrong type of id. (e.g. sending a UserId into a query for products)
This works through the use of an abstract base class (StrongTypedId<TStrongTypedId, TPrimitiveId>) which is inherited
to gain the id functionality.
This project is inspired by Andrew Lock's StronglyTypedId. However I needed support for .Net 5 and thus this project was born. It has since evolved to .Net 9.
Installation
I recommend using the NuGet package: StrongTypedId however feel free to clone the source instead if that suits your needs better.
Usage
Specify your class like this:
[StrongTypedIdJsonConverter<UserId, Guid>]
public class UserId: StrongTypedId<UserId, Guid>
{
public UserId(Guid value) : base(value)
{
}
}
This specifies that the class UserId is in fact a Guid and can be used in place of a Guid.
And that's basically all there is to it, now you just use UserId in place of Guid where you're dealing with an User'
s Id.
You can omit the JsonConverter if you don't use json serialization.
Furthermore there are a couple of base classes available to you:
StrongTypedValuefor anything that's not an id, this supportsstringas a primitive value.StrongTypedIdfor anything that IS an id, this only supportsstructtypes as primitives (therefore nostrings).- Adds the static
Parse(string)andTryParse(string, out TStrongTypedId)methods.
- Adds the static
StrongTypedGuida further specialization ofStrongTypedId.- Adds the static
New()method for instantiating new ids with random values as well as the staticEmptyproperty.
- Adds the static
Finally you can recognize a StrongTyped value by calling the extension method IsStrongTypedValue(). All strong typed
values furthermore implements both IStrongTypedValue<TPrimitiveValue> as well as IStrongTypedValue (The latter being
strictly a marker interface).
Documentation
Auto generated documentation via DocFx is available here: https://steffenskov.github.io/StrongTypedId/
Compatibility
Dapper.DDD.Repository
This can work without any extensions, however it's a bit simpler to use via the package StrongTypedId.Dapper.DDD.Repository.
Entity Framework
This is supported through the package StrongTypedId.EntityFrameworkCore.
WebAPI
This is supported through the use of the built-in JsonConverter.
MVC
This is supported out-of-the-box.
NewtonSoft.Json
This is supported through the package StrongTypedId.NewtonSoft.
Swagger
This is supported through the package StrongTypedId.Swagger.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
-
net9.0
- No dependencies.
NuGet packages (6)
Showing the top 5 NuGet packages that depend on StrongTypedId:
| Package | Downloads |
|---|---|
|
StrongTypedId.NewtonSoft
NewtonSoft.Json JsonConverter for the StrongTypedId library |
|
|
StrongTypedId.MongoDB
Serialization extension for easy usage of StrongTypedId with MongoDB. |
|
|
StrongTypedId.Dapper.DDD.Repository
TypeConverter extension for easy usage of StrongTypedId with the Dapper.DDD.Repository. |
|
|
StrongTypedId.EntityFrameworkCore
EntityFrame.Core ValueConverter for the StrongTypedId library |
|
|
StrongTypedId.Swagger
Swagger support for the StrongTypedId library |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.5.2 | 700 | 1/29/2026 |
| 2.5.1 | 507 | 10/15/2025 |
| 2.5.0 | 291 | 10/15/2025 |
| 2.4.0 | 4,113 | 8/17/2025 |
| 2.3.3 | 2,444 | 7/23/2025 |
| 2.3.2 | 571 | 7/21/2025 |
| 2.3.1 | 309 | 7/11/2025 |
| 2.3.0 | 327 | 7/6/2025 |
| 2.2.1 | 258 | 7/5/2025 |
| 2.2.0 | 1,458 | 3/12/2025 |
| 2.1.0 | 418 | 3/12/2025 |
| 2.0.0 | 8,516 | 12/30/2024 |
| 1.9.2 | 10,236 | 11/15/2024 |
| 1.9.1 | 331 | 11/13/2024 |
| 1.9.0 | 337 | 11/11/2024 |
| 1.8.0 | 15,334 | 8/26/2024 |
| 1.7.0 | 16,223 | 5/10/2024 |
| 1.6.6 | 8,513 | 2/9/2024 |
| 1.6.5 | 561 | 2/5/2024 |
| 1.6.4 | 392 | 1/31/2024 |