StrongTypedId 2.4.0
dotnet add package StrongTypedId --version 2.4.0
NuGet\Install-Package StrongTypedId -Version 2.4.0
<PackageReference Include="StrongTypedId" Version="2.4.0" />
<PackageVersion Include="StrongTypedId" Version="2.4.0" />
<PackageReference Include="StrongTypedId" />
paket add StrongTypedId --version 2.4.0
#r "nuget: StrongTypedId, 2.4.0"
#:package StrongTypedId@2.4.0
#addin nuget:?package=StrongTypedId&version=2.4.0
#tool nuget:?package=StrongTypedId&version=2.4.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.4.0 | 103 | 8/17/2025 |
2.3.3 | 1,090 | 7/23/2025 |
2.3.2 | 372 | 7/21/2025 |
2.3.1 | 144 | 7/11/2025 |
2.3.0 | 173 | 7/6/2025 |
2.2.1 | 104 | 7/5/2025 |
2.2.0 | 1,176 | 3/12/2025 |
2.1.0 | 232 | 3/12/2025 |
2.0.0 | 8,316 | 12/30/2024 |
1.9.2 | 9,945 | 11/15/2024 |
1.9.1 | 196 | 11/13/2024 |
1.9.0 | 182 | 11/11/2024 |
1.8.0 | 14,927 | 8/26/2024 |
1.7.0 | 16,088 | 5/10/2024 |
1.6.6 | 8,344 | 2/9/2024 |
1.6.5 | 425 | 2/5/2024 |
1.6.4 | 268 | 1/31/2024 |
1.6.3 | 889 | 1/8/2024 |
1.6.2 | 5,810 | 10/10/2023 |
1.6.1 | 641 | 9/8/2023 |
1.6.0 | 449 | 7/18/2023 |
1.5.1 | 534 | 7/15/2023 |
1.5.0 | 289 | 7/15/2023 |
1.4.3 | 432 | 7/11/2023 |
1.4.2 | 255 | 7/11/2023 |
1.4.1 | 283 | 7/11/2023 |
1.4.0 | 268 | 7/10/2023 |
1.3.0 | 1,198 | 5/21/2023 |
1.2.0 | 946 | 1/21/2023 |
1.1.7 | 2,883 | 12/7/2022 |
1.1.6 | 358 | 12/6/2022 |
1.1.5 | 684 | 8/5/2022 |
1.1.4 | 4,290 | 7/10/2022 |
1.1.3 | 923 | 7/10/2022 |
1.1.2 | 735 | 5/12/2022 |
1.1.1 | 1,158 | 3/12/2022 |
1.1.0 | 542 | 3/12/2022 |
1.0.3 | 478 | 3/12/2022 |
1.0.2 | 514 | 3/7/2022 |
1.0.1 | 519 | 3/6/2022 |
1.0.0 | 477 | 3/6/2022 |