EricksonLopez.DomainPrimitives
dotnet-domain-primitives · Modelado de Dominio
En esta página (20 secciones)
1. Identidad, Nivel y Perfil de Madurez#
2. Propuesta de Valor y Problema que Resuelve#
High-performance, AOT-ready Domain Primitives for .NET 8+. Generates secure, immutable value objects with deep BCL integration, including IUtf8SpanParsable, for robust domain modeling with minimal overhead.
Usar valores crudos string, Guid, int o decimal en fronteras de dominio permite que identificadores inválidos o intercambiados circulen sin control y duplica validaciones defensivas en servicios y repositorios.
3. Instalación Rápida#
Paquete principal: EricksonLopez.DomainPrimitives
dotnet add package EricksonLopez.DomainPrimitives --version 3.0.0<PackageReference Include="EricksonLopez.DomainPrimitives" Version="3.0.0" /><PackageVersion Include="EricksonLopez.DomainPrimitives" Version="3.0.0" />4. Métricas Verificadas del Ecosistema#
Instantánea recuperada UTC: 2026-12-01
5. Cuándo Usar y Cuándo NO Usar#
Cuándo usar
- Necesitas StrongIds, SmartEnums y primitivas validadas en tiempo de compilación mediante Roslyn Source Generators.
- Requieres parsing con spans del BCL (IParsable<T>, ISpanParsable<T>, IUtf8SpanParsable<T>) y adaptadores para EF Core o Dapper.
Cuándo NO usar
- Necesitas tipos de dominio compuestos como Money con CurrencyCode o identificadores fiscales regionales; usa EricksonLopez.ValueObjects en su lugar.
- Tu proyecto solo requiere DTOs simples de transferencia sin invariantes de dominio.
6. Capacidades Principales e Invariantes de Diseño#
Tipos de Valor en Stack
Genera primitivas readonly record struct y StrongIds con cero asignaciones en heap en rutas no basadas en string.
Source Generators y Analizadores Roslyn
Emite IParsable<T>, ISpanParsable<T>, IUtf8SpanParsable<T> e ISpanFormattable junto con diagnósticos DP0001–DP0018 en compilación.
Atajos Semánticos y Persistencia
Incluye atributos integrados ([Email], [CountryCode], [CurrencyCode], [Money]) y extensiones de registro para EF Core y Dapper.
7. Paquetes NuGet y Adaptadores Incluidos#
| ID del Paquete | Estado | NuGet / Local | TFMs | Estado AOT | Descargas | Descripción |
|---|---|---|---|---|---|---|
| EricksonLopez.DomainPrimitivesPrincipal | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0 | AOT: Completo | 525 | The definitive framework for Domain Primitives in .NET. Source-generated, NativeAOT-ready, zero-reflection strong IDs, value objects, validated types, and smart enums. This meta-package includes Abstractions, Source Generators, and Roslyn Analyzers. |
| EricksonLopez.DomainPrimitives.Abstractions | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0, netstandard2.0 | AOT: Completo | 3,352 | Core abstractions for domain primitives: marker interfaces, type declaration attributes, validation attributes, and normalization attributes. Zero dependencies — pure attributes and interfaces only. NativeAOT and trimming compatible. |
| EricksonLopez.DomainPrimitives.OpenApi | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0 | AOT: Completo | 472 | OpenAPI/Swashbuckle integration for EricksonLopez.DomainPrimitives. Generates precise schema specifications for domain primitives. |
| EricksonLopez.DomainPrimitives.AspNetCore | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0 | AOT: Completo | 457 | ASP.NET Core integration for EricksonLopez.DomainPrimitives. Automatically generates ModelBinders and Swagger/OpenAPI schemas for Domain Primitives. |
| EricksonLopez.DomainPrimitives.Dapper | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0 | AOT: Completo | 457 | Dapper integration for EricksonLopez.DomainPrimitives. Automatically generates NativeAOT-ready SqlMapper.TypeHandler implementations for all domain primitives without reflection. |
| EricksonLopez.DomainPrimitives.Testing | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0 | AOT: Parcial | 447 | Testing library for EricksonLopez.DomainPrimitives. Provides Assertions, Builders, and Fakes for unit testing your domain primitives seamlessly with xUnit, NSubstitute and AwesomeAssertions. |
| EricksonLopez.DomainPrimitives.EFCore | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0 | AOT: Completo | 438 | EF Core integration for EricksonLopez.DomainPrimitives. Automatically generates NativeAOT-ready ValueConverters for all domain primitives without reflection. |
| EricksonLopez.DomainPrimitives.NewtonsoftJson | Publicado | v3.0.0 / v4.1.0 | net8.0, net9.0, net10.0 | AOT: Incompatible | 299 | [LEGACY COMPATIBILITY] Newtonsoft.Json (Json.NET) converters and contract resolver for EricksonLopez.DomainPrimitives. Note: Newtonsoft.Json uses heavy runtime reflection and is not NativeAOT or trimming compatible. |
| EricksonLopez.DomainPrimitives.OpenApi.SourceGeneratorsAnalizador / Generador | Publicado | v3.0.0 / v4.1.0 | netstandard2.0 | AOT: N/A (Analizador/Legado) | 654 | Source Generators for OpenApi integration with EricksonLopez.DomainPrimitives. |
| EricksonLopez.DomainPrimitives.GeneratorsAnalizador / Generador | Publicado | v3.0.0 / v4.1.0 | netstandard2.0 | AOT: N/A (Analizador/Legado) | 468 | Incremental Source Generators for EricksonLopez.DomainPrimitives. Generates complete domain primitive implementations at compile time: factory methods, parsing, formatting, equality, operators, and validation. Zero runtime footprint. |
| EricksonLopez.DomainPrimitives.AnalyzersAnalizador / Generador | Publicado | v3.0.0 / v4.1.0 | netstandard2.0 | AOT: N/A (Analizador/Legado) | 458 | Roslyn Analyzers and Code Fixes for EricksonLopez.DomainPrimitives. Detects misuse at compile time: public constructors, bypassed validation, conflicting attributes, missing partial keywords, and more. |
| EricksonLopez.DomainPrimitives.AspNetCore.SourceGeneratorsAnalizador / Generador | Publicado | v3.0.0 / v4.1.0 | netstandard2.0 | AOT: N/A (Analizador/Legado) | 440 | Source Generators for ASP.NET Core integration with EricksonLopez.DomainPrimitives. |
| EricksonLopez.DomainPrimitives.Dapper.SourceGeneratorsAnalizador / Generador | Publicado | v3.0.0 / v4.1.0 | netstandard2.0 | AOT: N/A (Analizador/Legado) | 440 | Source Generators for Dapper integration with EricksonLopez.DomainPrimitives. |
| EricksonLopez.DomainPrimitives.EFCore.SourceGeneratorsAnalizador / Generador | Publicado | v3.0.0 / v4.1.0 | netstandard2.0 | AOT: N/A (Analizador/Legado) | 438 | Source Generators for EF Core integration with EricksonLopez.DomainPrimitives. |
8. Ejemplo Quick Start#
Basado en APIs públicas verificadas de EricksonLopez.DomainPrimitives. Compila con `<ImplicitUsings>disable</ImplicitUsings>` e importaciones explícitas.
using EricksonLopez.DomainPrimitives;
CountryIsoCode code = CountryIsoCode.Create(" us "); // "US"
EmailAddress email = EmailAddress.Create("user@example.com");
[StringPrimitive]
[Trim, UpperCase, Length(2, 2)]
public readonly partial record struct CountryIsoCode;
[Email]
public readonly partial record struct EmailAddress;9. Arquitectura y Flujo de Dependencias#
Renderizando diagrama…
flowchart LR lib_domain_primitives["EricksonLopez.DomainPrimitives (L0)"] lib_shared_kernel["EricksonLopez.SharedKernel (L1)"] lib_shared_kernel --> lib_domain_primitives lib_value_objects["EricksonLopez.ValueObjects (L1)"] lib_value_objects --> lib_domain_primitives lib_mapper["EricksonLopez.Mapper (L2)"] lib_mapper --> lib_domain_primitives
Ver descripción textual y tabla accesible
0 dependencias hacia librerías aguas arriba y 3 librerías dependientes aguas abajo verificadas en dependencies.json.
| Dirección | Librería | Nivel | Tipos de Relación |
|---|---|---|---|
| Aguas abajo | EricksonLopez.SharedKernel | L1 | Adaptador, Tiempo de compilación, Paquete NuGet |
| Aguas abajo | EricksonLopez.ValueObjects | L1 | Tiempo de compilación, Paquete NuGet |
| Aguas abajo | EricksonLopez.Mapper | L2 | Tiempo de compilación, Paquete NuGet |
flowchart LR
lib_domain_primitives["EricksonLopez.DomainPrimitives (L0)"]
lib_shared_kernel["EricksonLopez.SharedKernel (L1)"]
lib_shared_kernel --> lib_domain_primitives
lib_value_objects["EricksonLopez.ValueObjects (L1)"]
lib_value_objects --> lib_domain_primitives
lib_mapper["EricksonLopez.Mapper (L2)"]
lib_mapper --> lib_domain_primitives10. Target Frameworks y Matriz Native AOT / Trimming#
Inspección MSBuild `.csproj` sobre 14 paquetes: 6 Full, 1 Partial, 1 Incompatible, 6 NotApplicable (analizadores/generadores).
| ID del Paquete | IsAotCompatible | EnableTrimAnalyzer | Estado AOT Verificado | Target Frameworks |
|---|---|---|---|---|
| EricksonLopez.DomainPrimitives | true | true | Full | net8.0, net9.0, net10.0 |
| EricksonLopez.DomainPrimitives.Abstractions | true | true | Full | net8.0, net9.0, net10.0, netstandard2.0 |
| EricksonLopez.DomainPrimitives.OpenApi | true | true | Full | net8.0, net9.0, net10.0 |
| EricksonLopez.DomainPrimitives.AspNetCore | true | true | Full | net8.0, net9.0, net10.0 |
| EricksonLopez.DomainPrimitives.Dapper | true | true | Full | net8.0, net9.0, net10.0 |
| EricksonLopez.DomainPrimitives.Testing | true | false | Partial | net8.0, net9.0, net10.0 |
| EricksonLopez.DomainPrimitives.EFCore | true | true | Full | net8.0, net9.0, net10.0 |
| EricksonLopez.DomainPrimitives.NewtonsoftJson | false | false | Incompatible | net8.0, net9.0, net10.0 |
| EricksonLopez.DomainPrimitives.OpenApi.SourceGenerators | null | null | NotApplicable | netstandard2.0 |
| EricksonLopez.DomainPrimitives.Generators | null | null | NotApplicable | netstandard2.0 |
| EricksonLopez.DomainPrimitives.Analyzers | null | null | NotApplicable | netstandard2.0 |
| EricksonLopez.DomainPrimitives.AspNetCore.SourceGenerators | null | null | NotApplicable | netstandard2.0 |
| EricksonLopez.DomainPrimitives.Dapper.SourceGenerators | null | null | NotApplicable | netstandard2.0 |
| EricksonLopez.DomainPrimitives.EFCore.SourceGenerators | null | null | NotApplicable | netstandard2.0 |
11. Dependencias Aguas Arriba y Dependientes Aguas Abajo#
Dependencias Aguas Arriba (0)
Cero dependencias cruzadas aguas arriba (nodo fundacional).
Dependientes Aguas Abajo (3)
12. Adaptadores Opcionales e Integraciones Externas#
Aristas de Adaptadores Internos y Paquetes de Integración
- EricksonLopez.SharedKernel.Dapper (EricksonLopez.SharedKernel)→ EricksonLopez.DomainPrimitives.Abstractions
Dependencias NuGet Externas Verificadas (7)
13. Resumen de Configuración y Registro en DI#
Puntos de Entrada DI y Configuración Verificados
DomainPrimitivesMvcBuilderExtensions.AddDomainPrimitivesModelBindingAdds domain primitive model binding to the service collection.
NewtonsoftJsonExtensions.AddDomainPrimitivesAdds the universal domain primitive JSON converter to the serializer.
Tipos Públicos y Contratos Clave
EricksonLopez.DomainPrimitives.AgeAttribute (class)Specifies that a struct is an age domain primitive. Equivalent to: `[NumericPrimitive<int>] [PrimitiveRange(0, 150)]`.
EricksonLopez.DomainPrimitives.BirthDateAttribute (class)Specifies that a struct is a birth date domain primitive. Equivalent to: `[DatePrimitive(Kind = DateOnly, PastOnly = true)]`.
EricksonLopez.DomainPrimitives.BusinessDateAttribute (class)Specifies that a struct is a business date domain primitive.
EricksonLopez.DomainPrimitives.CountryCodeAttribute (class)Specifies that a struct is an ISO 3166-1 alpha-2 country code (e.g., "US", "DE"). Equivalent to: `[StringPrimitive] [Trim] [UpperCase] [Length(2, 2)]`.
EricksonLopez.DomainPrimitives.CurrencyCodeAttribute (class)Specifies that a struct is an ISO 4217 currency code (e.g., "USD", "EUR"). Equivalent to: `[StringPrimitive] [Trim] [UpperCase] [Length(3, 3)]`.
EricksonLopez.DomainPrimitives.DatePrimitiveAttribute (class)Specifies that a struct is a date- or time-backed domain primitive.
EricksonLopez.DomainPrimitives.DatePrimitiveKind (enum)Specifies the backing temporal type for a date primitive.
EricksonLopez.DomainPrimitives.DateRangeAttribute (class)Specifies that a struct is a date range domain primitive. Architectural Guidance: In Domain-Driven Design, when modeling a compound interval with both start and end timestamps and cross-property validation (`Start <= End`), prefer creating a compound `[ValueObject]`.
EricksonLopez.DomainPrimitives.DiscountAttribute (class)Specifies that a struct is a discount domain primitive. Equivalent to: `[NumericPrimitive<decimal>] [PrimitiveRange(0, 100)]`.
EricksonLopez.DomainPrimitives.DistanceAttribute (class)Specifies that a struct is a distance domain primitive. Equivalent to: `[NumericPrimitive<double>] [PrimitiveRange(0, double.MaxValue)]`.
EricksonLopez.DomainPrimitives.DomainPrimitiveValidationException (class)Represents the exception thrown when a domain primitive cannot be created due to invalid input.
EricksonLopez.DomainPrimitives.DomainPrimitivesDefaultsAttribute (class)Specifies global default policies for domain primitives generated in this assembly.
14. Benchmarks de Rendimiento Verificados#
Todas las mediciones verificadas provienen estrictamente de `BenchmarkDotNet.Artifacts` ejecutados sobre .NET RyuJIT (existen 0 ejecuciones NativeAOT en esta instantánea).
| Suite | Método | Runtime | Media (ns) | Asignado (B) | Estado |
|---|---|---|---|---|---|
| ComparativeBenchmarks | ValueObject_Create | .NET 9.0.20 X64 RyuJIT x86-64-v3 | 0.001 | 0 | measured |
| DomainPrimitiveBenchmarks | RawGuid | .NET 9.0.20 X64 RyuJIT x86-64-v3 | 0.114 | 0 | measured |
| ComparativeBenchmarks | StronglyTypedId_Create | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.134 | 0 | measured |
| ComparativeBenchmarks | Meziantou_Create | .NET 9.0.20 X64 RyuJIT x86-64-v3 | 0.164 | 0 | measured |
| ComparativeBenchmarks | Meziantou_Create | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.167 | 0 | measured |
| ComparativeBenchmarks | TinyTypes_Create | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.171 | 0 | measured |
| ComparativeBenchmarks | StronglyTypedId_Create | .NET 9.0.20 X64 RyuJIT x86-64-v3 | 0.173 | 0 | measured |
| ComparativeBenchmarks | StronglyTypedId_Create | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.192 | 0 | measured |
| ComparativeBenchmarks | RawGuid_Create | .NET 9.0.20 X64 RyuJIT x86-64-v3 | 0.216 | 0 | measured |
| ComparativeBenchmarks | TinyTypes_Create | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.247 | 0 | measured |
| ComparativeBenchmarks | RawGuid_Create | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.253 | 0 | measured |
| ComparativeBenchmarks | Meziantou_Create | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.309 | 0 | measured |
| DomainPrimitiveBenchmarks | RawGuid | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.314 | 0 | measured |
| DomainPrimitiveBenchmarks | RawGuid | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.324 | 0 | measured |
| ComparativeBenchmarks | ValueObject_Create | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.325 | 0 | measured |
| ComparativeBenchmarks | ValueObject_Create | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.331 | 0 | measured |
| ComparativeBenchmarks | RawGuid_Create | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.338 | 0 | measured |
| ComparativeBenchmarks | Dapper_TypeHandler_SetValue | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.345 | 0 | measured |
| ComparativeBenchmarks | Vogen_Create | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.384 | 0 | measured |
| ComparativeBenchmarks | Vogen_Create | .NET 9.0.20 X64 RyuJIT x86-64-v3 | 0.547 | 0 | measured |
| ComparativeBenchmarks | DomainPrimitives_EqualityCheck | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.798 | 0 | measured |
| DomainPrimitiveBenchmarks | PrimitiveGuid | .NET 9.0.20 X64 RyuJIT x86-64-v3 | 0.852 | 0 | measured |
| ComparativeBenchmarks | DomainPrimitives_Create | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.87 | 0 | measured |
| ComparativeBenchmarks | EFCore_ValueConverter_ConvertFromProvider | .NET 10.0.12 X64 RyuJIT x86-64-v3 | 0.879 | 0 | measured |
| DomainPrimitiveBenchmarks | PrimitiveGuid | .NET 8.0.31 X64 RyuJIT x86-64-v3 | 0.882 | 0 | measured |
15. Historial de Versiones y Estado NuGet vs Repositorio#
Desfase de versiones detectado: la última versión publicada en NuGet.org es v3.0.0, mientras el HEAD del repositorio local está en v4.1.0.
| Versión | Origen | Fecha de Publicación | Resumen |
|---|---|---|---|
| v3.0.0 ↗ | nuget | 2026-09-20 | Published EricksonLopez.DomainPrimitives 3.0.0 to NuGet.org. |
| v3.0.0 ↗ | github | 2026-09-20 | Ecosystem Packages in this release | Package | Version | |---------|---------| | `EricksonLopez.DomainPrimitives.Abstractions` | `3.0.0` | | `EricksonLopez.DomainPrimitives` | `3.0.0` | | `EricksonLopez.DomainPrimitives.Generators` | `3.0.0` | | `EricksonLopez.DomainPrimitives.Analyzers` | `3.0.0` | | `EricksonLopez.DomainPrimitives.AspNetCore` | `3.0.0` | | `EricksonLopez.DomainPrimitives.AspN... |
| v2.0.0 ↗ | nuget | 2026-08-25 | Published EricksonLopez.DomainPrimitives 2.0.0 to NuGet.org. |
| v2.0.0 ↗ | github | 2026-08-25 | Ecosystem Packages in this release | Package | Version | |---------|---------| | `EricksonLopez.DomainPrimitives.Abstractions` | `2.0.0` | | `EricksonLopez.DomainPrimitives` | `2.0.0` | | `EricksonLopez.DomainPrimitives.Generators` | `2.0.0` | | `EricksonLopez.DomainPrimitives.Analyzers` | `2.0.0` | | `EricksonLopez.DomainPrimitives.AspNetCore` | `2.0.0` | | `EricksonLopez.DomainPrimitives.AspN... |
| v1.0.0 ↗ | github | 2026-08-11 | Ecosystem Packages in this release | Package | Version | |---------|---------| | `EricksonLopez.DomainPrimitives` | `1.0.0` | | `EricksonLopez.DomainPrimitives.Generators` | `1.0.0` | | `EricksonLopez.DomainPrimitives.Abstractions` | `1.0.0` | | `EricksonLopez.DomainPrimitives.Analyzers` | `1.0.0` | | `EricksonLopez.DomainPrimitives.AspNetCore` | `1.0.0` | | `EricksonLopez.DomainPrimitives.AspN... |
| v1.0.0 ↗ | nuget | 2026-08-11 | Published EricksonLopez.DomainPrimitives 1.0.0 to NuGet.org. |
16. Librerías Complementarias y Relacionadas#
Librerías en el mismo nivel, capa arquitectónica o vinculadas directamente mediante aristas de dependencia.
17. Documentación, API Reference y Enlaces del Portal#
Documentación Conceptual (Starlight) →
Referencia de API XML Extraída →
11 namespaces · 117 tipos · 298 miembros
Mapa de Dependencias del Ecosistema →
Centro de Aprendizaje y Manual →
Las páginas conceptuales por librería en Starlight se completan en M4; las páginas de API Reference en M3.2.
18. Repositorio Fuente, Licencia y Contribución#
Publicado bajo Licencia MIT. Todos los ensamblados cumplen los invariantes de compilación EricksonLopez.*: importaciones explícitas, firma fuerte (`EricksonLopez.snk`) y metadatos de autor en ASCII (`Erickson Lopez`).
19. Resolución de Problemas, Riesgos y Migración#
- Declara explícitamente partial en tus readonly record struct para que los generadores incrementales emitan las interfaces del BCL.
- Verifica el estado AOT por paquete: el núcleo es Full AOT, mientras los adaptadores de Newtonsoft.Json y SwaggerGen son Partial o Incompatible.
- Desfase de versiones detectado: la última versión publicada en NuGet.org es v3.0.0, mientras el HEAD del repositorio local está en v4.1.0.
20. Evidencia de Calidad y Verificación#
- Firma Fuerte (`EricksonLopez.snk`)
- EricksonLopez.snk
- `ImplicitUsings=disable`
- disable
- Extracción de Documentación XML
- Verificado (11 namespaces, 117 tipos, 298 miembros)
- Atributos MSBuild AOT / Trimming
- 6 Full / 1 Partial / 1 Incompatible / 6 N/A
- Artefactos BenchmarkDotNet
- 155 total (151 measured, 4 na_error)
Límites Explícitos de Verificación y Alcance
- Todas las mediciones verificadas provienen estrictamente de `BenchmarkDotNet.Artifacts` ejecutados sobre .NET RyuJIT (existen 0 ejecuciones NativeAOT en esta instantánea).