Allegro.Extensions.Identifiers.Abstractions
1.1.1
Prefix Reserved
See the version list below for details.
dotnet add package Allegro.Extensions.Identifiers.Abstractions --version 1.1.1
NuGet\Install-Package Allegro.Extensions.Identifiers.Abstractions -Version 1.1.1
<PackageReference Include="Allegro.Extensions.Identifiers.Abstractions" Version="1.1.1" />
paket add Allegro.Extensions.Identifiers.Abstractions --version 1.1.1
#r "nuget: Allegro.Extensions.Identifiers.Abstractions, 1.1.1"
// Install Allegro.Extensions.Identifiers.Abstractions as a Cake Addin #addin nuget:?package=Allegro.Extensions.Identifiers.Abstractions&version=1.1.1 // Install Allegro.Extensions.Identifiers.Abstractions as a Cake Tool #tool nuget:?package=Allegro.Extensions.Identifiers.Abstractions&version=1.1.1
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 | Versions 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. |
-
net6.0
- Meziantou.Framework.StronglyTypedId (= 1.0.22)
- Microsoft.CodeAnalysis (= 4.2.0)
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.