-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The Identifiers.AspNetCore library solves the problem of using int or guid as a Id. An Id should be represented by a special type. This library gives you the Identifier type.
Before creating this type I was reading some great articles which helped me a lot.
https://andrewlock.net/using-strongly-typed-entity-ids-to-avoid-primitive-obsession-part-1/ https://www.martinfowler.com/bliki/ValueObject.html https://lostechies.com/jimmybogard/2007/12/03/dealing-with-primitive-obsession/
This library is Cross-platform, supporting netstandard2.1.
Install via NuGet first:
Install-Package Identifiers
Identifiers has no dependencies.
To use it:
using Identifiers;
public class Order
{
public Identifier Id { get; set; }
...If you're using ASP.NET Core and you want to use this Identifier type in your models, then you can use Identifiers.AspNetCore package which includes a IServiceCollection.AddIdentifiers<[InternalClrType:short|int|long|Guid]>() extension method, allowing you to register all needed RouteConstraints, ModelBinders and JsonConverters.
If you're using EntityFrameworkCore and you want to use this Identifier type in your entities, then you can use Identifiers.EntityFrameworkCore package which includes a DbContextOptionsBuilder.UseIdentifiers<[InternalClrType:short|int|long|Guid]>() extension method, allowing you to register all needed IValueConverterSelectors and IMigrationsAnnotationProviders.
It also includes a PropertyBuilder<Identifier>.IdentifierValueGeneratedOnAdd() extension method, allowing you to register all needed configuration to use SqlServerValueGenerationStrategy.IdentityColumn.