Allegro.Extensions.Identifiers.Abstractions 1.4.0

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

// Install Allegro.Extensions.Identifiers.Abstractions as a Cake Tool
#tool nuget:?package=Allegro.Extensions.Identifiers.Abstractions&version=1.4.0                

Allegro.Extensions.Identifiers

In most scenarios in microservice architecture (but not only) in communication between services some kind of identifiers are passed.

Commonly, they are passed in body or in url as string ex.:

http://serviceName/{userid}/resource/{id}

or

{
    "userId": "value",
    "paymentId": "value"
}

Additionally in code it might be passed like:

Task ExecuteCommand(string userId, string paymentId) { ... }

In this case compiler is not defending as from switching parameters by mistake in wrong order (both are strings) that might cause serious issues. Primitive obsession code smell teaches as to wrap our primitive data structure into strongly typed objects to prevent from this kind of issues.

This is why we try to use strongly typed identifiers in our code as fast (high) as possible, ex.:

Task ExecuteCommand(UserId userId, PaymentId paymentId) { ... }

Allegro.Extensions.Identifiers.Abstractions

To standardize our approach between services we introduced marker interface for strongly typed identifier:

public interface IStronglyTypedId<out T>
{
    public T Value { get; }

    public string ValueAsString { get; }
}

To be able to use them in api or store in db without additional data structure we want still to use string in api but use strongly typed in code base:

http://serviceName/123123123/order/13af7673-593c-4b7f-9d99-7c45faadb1e1

[Get("{userId}/payemnt/{orderId}")]
public Task Action([FromRoute] UserId userId,[FromRoute] OrderId orderId) { ... }

To achieve that we use code generation framework delivered by package Meziantou.Framework.StronglyTypedId with usage:

[StronglyTypedId(typeof(Guid))]
public partial class OrderId : IStronglyTypedId<Guid>
{
}

More examples can be found in demo.

Allegro.Extensions.Identifiers.AspNetCore

To be able to use strongly typed identifiers in api/contracts and still use swagger for testing purposes some code hints need to be added to learn swagger how to interpret them.

In this package you can find extensions to support strongly type identifiers by swagger. They are based on marker interface IStronglyTypedId<out T>.

Usage can be found here demo.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Allegro.Extensions.Identifiers.Abstractions:

Package Downloads
Allegro.Extensions.Identifiers.AspNetCore

Contains strongly typed identifiers extensions for swagger.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.4.0 176 2/5/2024
1.3.0 138 1/26/2024
1.2.0 2,735 1/4/2023
1.1.1 370 1/3/2023
1.1.0 434 11/15/2022
1.0.0 459 11/7/2022