StrongTypedId 2.3.0
dotnet add package StrongTypedId --version 2.3.0
NuGet\Install-Package StrongTypedId -Version 2.3.0
<PackageReference Include="StrongTypedId" Version="2.3.0" />
<PackageVersion Include="StrongTypedId" Version="2.3.0" />
<PackageReference Include="StrongTypedId" />
paket add StrongTypedId --version 2.3.0
#r "nuget: StrongTypedId, 2.3.0"
#addin nuget:?package=StrongTypedId&version=2.3.0
#tool nuget:?package=StrongTypedId&version=2.3.0
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:
[StrongTypedValueJsonConverterFactory]
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:
StrongTypedValue
for anything that's not an id, this supportsstring
as a primitive value.StrongTypedId
for anything that IS an id, this only supportsstruct
types as primitives (therefore nostrings
).- Adds the static
Parse(string)
andTryParse(string, out TStrongTypedId)
methods.
- Adds the static
StrongTypedGuid
a further specialization ofStrongTypedId
.- Adds the static
New()
method for instantiating new ids with random values as well as the staticEmpty
property.
- 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 (5)
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.3.0 | 43 | 7/6/2025 |
2.2.1 | 38 | 7/5/2025 |
2.2.0 | 1,040 | 3/12/2025 |
2.1.0 | 213 | 3/12/2025 |
2.0.0 | 8,256 | 12/30/2024 |
1.9.2 | 9,898 | 11/15/2024 |
1.9.1 | 180 | 11/13/2024 |
1.9.0 | 167 | 11/11/2024 |
1.8.0 | 14,913 | 8/26/2024 |
1.7.0 | 16,073 | 5/10/2024 |
1.6.6 | 8,328 | 2/9/2024 |
1.6.5 | 412 | 2/5/2024 |
1.6.4 | 258 | 1/31/2024 |
1.6.3 | 867 | 1/8/2024 |
1.6.2 | 5,798 | 10/10/2023 |
1.6.1 | 621 | 9/8/2023 |
1.6.0 | 427 | 7/18/2023 |
1.5.1 | 511 | 7/15/2023 |
1.5.0 | 269 | 7/15/2023 |
1.4.3 | 412 | 7/11/2023 |
1.4.2 | 236 | 7/11/2023 |
1.4.1 | 262 | 7/11/2023 |
1.4.0 | 247 | 7/10/2023 |
1.3.0 | 1,179 | 5/21/2023 |
1.2.0 | 926 | 1/21/2023 |
1.1.7 | 2,816 | 12/7/2022 |
1.1.6 | 337 | 12/6/2022 |
1.1.5 | 658 | 8/5/2022 |
1.1.4 | 4,223 | 7/10/2022 |
1.1.3 | 895 | 7/10/2022 |
1.1.2 | 709 | 5/12/2022 |
1.1.1 | 1,133 | 3/12/2022 |
1.1.0 | 517 | 3/12/2022 |
1.0.3 | 451 | 3/12/2022 |
1.0.2 | 489 | 3/7/2022 |
1.0.1 | 497 | 3/6/2022 |
1.0.0 | 451 | 3/6/2022 |