Allegro.Extensions.Identifiers.AspNetCore 1.1.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Allegro.Extensions.Identifiers.AspNetCore --version 1.1.0                
NuGet\Install-Package Allegro.Extensions.Identifiers.AspNetCore -Version 1.1.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.AspNetCore" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Allegro.Extensions.Identifiers.AspNetCore --version 1.1.0                
#r "nuget: Allegro.Extensions.Identifiers.AspNetCore, 1.1.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.AspNetCore as a Cake Addin
#addin nuget:?package=Allegro.Extensions.Identifiers.AspNetCore&version=1.1.0

// Install Allegro.Extensions.Identifiers.AspNetCore as a Cake Tool
#tool nuget:?package=Allegro.Extensions.Identifiers.AspNetCore&version=1.1.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

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.4.0 148 2/5/2024
1.3.0 116 1/26/2024
1.2.0 808 1/4/2023
1.1.1 297 1/3/2023
1.1.0 336 11/15/2022
1.0.0 349 11/7/2022