TT.DomainTypes
1.0.0
dotnet add package TT.DomainTypes --version 1.0.0
NuGet\Install-Package TT.DomainTypes -Version 1.0.0
<PackageReference Include="TT.DomainTypes" Version="1.0.0" />
<PackageVersion Include="TT.DomainTypes" Version="1.0.0" />
<PackageReference Include="TT.DomainTypes" />
paket add TT.DomainTypes --version 1.0.0
#r "nuget: TT.DomainTypes, 1.0.0"
#:package TT.DomainTypes@1.0.0
#addin nuget:?package=TT.DomainTypes&version=1.0.0
#tool nuget:?package=TT.DomainTypes&version=1.0.0
TT.DomainTypes
A record based solution to the primitive type obsession problem
The problem:
We use primitive types like strings and integers everywhere and we occassionally run into issues where the wrong string variable is passed into a function.
public static string GetExistingUserName(string userName)
{
...
}
However this could be accidentally used as so:
public static void Main()
{
string userName = ReadFromPrivateFunction();
string favouriteFood = ReadFromOtherPrivateFunction();
var existingUserName = GetExistingUserName(favouriteFood); //Nothing stops us from doing this
}
However, if we were to use a domain type, we would get a compile type error preventing us from making such a mistake
public record UserName(string Value) : DomainTypeString(Value);
public record Food(string Value) : DomainTypeString(Value);
Now that we have the Domain Types, that are backed by the record reference type, we can now get intellisense and compile errors.
Now our functions become
public static UserName GetExistingUserName(UserName userName)
{
...
}
public static void Main()
{
UserName userName = ReadFromPrivateFunction();
Food favouriteFood = ReadFromOtherPrivateFunction();
var existingUserName = GetExistingUserName(favouriteFood); //Compile time error here because we cannot assign a Food domain type to a UserName domain type
}
We also get the benefit of intellisense which we help us autocomplete or recommend local variables that match the required domain type.
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 was computed. 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. |
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on TT.DomainTypes:
Package | Downloads |
---|---|
TT.DomainTypes.Interop.Swagger
Interop library that enables TT.DomainTypes to be used with Swagger |
|
TT.DomainTypes.Interop.Dapper
Interop library that enables TT.DomainTypes to be used with Dapper |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 161 | 4/10/2024 |