StronglyTypedIds 1.0.1

dotnet add package StronglyTypedIds --version 1.0.1
NuGet\Install-Package StronglyTypedIds -Version 1.0.1
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="StronglyTypedIds" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StronglyTypedIds --version 1.0.1
#r "nuget: StronglyTypedIds, 1.0.1"
#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.
// Install StronglyTypedIds as a Cake Addin
#addin nuget:?package=StronglyTypedIds&version=1.0.1

// Install StronglyTypedIds as a Cake Tool
#tool nuget:?package=StronglyTypedIds&version=1.0.1

.NET

StronglyTypedIds

StronglyTypedIds helps to type entity identifiers for compile-time checking.

What problem are we solving?

Quite often, Guid, int, long, or string are used as identifiers for domain entities. Identifiers can be passed as arguments:

void AssignContractResponsible(Guid contractId, Guid employeeId);

In this example, 2 identifiers are used. You can only determine which one is which by the name of the argument. One day you can make a mistake and pass the identifiers in the wrong order. The problem is exacerbated if there are entities with similar names in the domain:

Contract и Contractor
Order и OrderTemplate
PriceList и PricePosition

Another example:

IDictionary<Guid, Contract> GetContractsByClients(IEnumerable<Guid> clientIds);

In this case, the client's identifier will probably act as the key of the dictionary. But we can't know this for sure, unless we look at the implementation.

Solution

The proposed solution is to pass not only the value of the identifier, but also the type of the identifiable entity.

So instead of:

void AssignContractResponsible(Guid contractId, Guid employeeId);

It becomes:

void AssignContractResponsible(GuidFor<Contract> contractId, GuidFor<Person> employeeId);

And instead of:

IDictionary<Guid, Contract> GetContractsByClients(IEnumerable<Guid> clientIds);

It will be:

IDictionary<GuidFor<Client>, Contract> GetContractsByClients(IEnumerable<GuidFor<Client>> clientIds);

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 396 11/25/2023
1.0.0 99 11/19/2023