Pitasoft.ObjectMapping.DependencyInjectionExtensions
1.0.1
dotnet add package Pitasoft.ObjectMapping.DependencyInjectionExtensions --version 1.0.1
NuGet\Install-Package Pitasoft.ObjectMapping.DependencyInjectionExtensions -Version 1.0.1
<PackageReference Include="Pitasoft.ObjectMapping.DependencyInjectionExtensions" Version="1.0.1" />
<PackageVersion Include="Pitasoft.ObjectMapping.DependencyInjectionExtensions" Version="1.0.1" />
<PackageReference Include="Pitasoft.ObjectMapping.DependencyInjectionExtensions" />
paket add Pitasoft.ObjectMapping.DependencyInjectionExtensions --version 1.0.1
#r "nuget: Pitasoft.ObjectMapping.DependencyInjectionExtensions, 1.0.1"
#:package Pitasoft.ObjectMapping.DependencyInjectionExtensions@1.0.1
#addin nuget:?package=Pitasoft.ObjectMapping.DependencyInjectionExtensions&version=1.0.1
#tool nuget:?package=Pitasoft.ObjectMapping.DependencyInjectionExtensions&version=1.0.1
Pitasoft.ObjectMapping.DependencyInjectionExtensions
English
Pitasoft.ObjectMapping.DependencyInjectionExtensions provides seamless IServiceCollection integration for the Pitasoft.ObjectMapping library. It is the recommended way to use the mapper in ASP.NET Core and modern backend applications.
Key Benefits
- Automatic Service Registration: Registers
IObjectMapperandObjectMappingConfigurationas singletons. - Profile Discovery: Automatically scans assemblies to find and register your
ObjectMappingProfileclasses. - Fail-Fast Startup Validation: Ensure all mappings are valid before the application starts, preventing runtime errors.
- Cold-Start Optimization: Precompiles configured maps during startup to eliminate latency spikes on the first mapping request.
Installation
Install via NuGet:
dotnet add package Pitasoft.ObjectMapping.DependencyInjectionExtensions
Note: This package depends on Pitasoft.ObjectMapping, which will be installed automatically.
Quick Start
1. Register Services
In your Program.cs or Startup.cs:
using Pitasoft.ObjectMapping.DependencyInjection;
// Minimal registration (manual mapping configuration)
builder.Services.AddObjectMapping();
// Recommended: Registration with assembly scanning
builder.Services.AddObjectMapping(typeof(UserMappingProfile).Assembly);
// Advanced: Registration with startup validation and precompilation
builder.Services.AddObjectMapping(
new[] { typeof(UserMappingProfile).Assembly },
configureRegistration: options =>
{
options.ValidateOnStartup = true; // Throws on startup if maps are invalid
options.PrecompileOnStartup = true; // Compiles maps immediately
options.ValidationMode = ObjectMappingValidationMode.AllWritableDestinationMembers;
});
2. Create a Mapping Profile
using Pitasoft.ObjectMapping.Configuration;
public class UserMappingProfile : ObjectMappingProfile
{
public override void Configure(ObjectMappingConfiguration configuration)
{
configuration.CreateMap<UserEntity, UserDto>()
.ToMember(dest => dest.FullName).FromMember(src => $"{src.FirstName} {src.LastName}");
}
}
3. Inject and Use
public class UserService(IObjectMapper mapper)
{
public UserDto GetUserDto(UserEntity entity)
{
// Simple mapping
return mapper.MapTo<UserEntity, UserDto>(entity);
}
}
Castellano
Pitasoft.ObjectMapping.DependencyInjectionExtensions proporciona una integración fluida con IServiceCollection para la librería Pitasoft.ObjectMapping. Es la forma recomendada de utilizar el mapeador en aplicaciones ASP.NET Core y backends modernos.
Beneficios Clave
- Registro Automático de Servicios: Registra
IObjectMapperyObjectMappingConfigurationcomo singletons en el contenedor DI. - Descubrimiento de Perfiles: Escanea automáticamente ensamblados para encontrar y registrar tus clases
ObjectMappingProfile. - Validación en el Arranque (Fail-Fast): Asegura que todos los mapeos sean válidos antes de que la aplicación comience a recibir tráfico, evitando errores en tiempo de ejecución.
- Optimización de Inicio en Frío: Precompila los mapas configurados durante el inicio para eliminar picos de latencia en la primera petición de mapeo.
Instalación
Instalar vía NuGet:
dotnet add package Pitasoft.ObjectMapping.DependencyInjectionExtensions
Nota: Este paquete depende de Pitasoft.ObjectMapping, que se instalará automáticamente.
Inicio Rápido
1. Registro de Servicios
En tu Program.cs o Startup.cs:
using Pitasoft.ObjectMapping.DependencyInjection;
// Registro mínimo (configuración de mapeo manual)
builder.Services.AddObjectMapping();
// Recomendado: Registro con escaneo de ensamblados
builder.Services.AddObjectMapping(typeof(UserMappingProfile).Assembly);
// Avanzado: Registro con validación y precompilación en el arranque
builder.Services.AddObjectMapping(
new[] { typeof(UserMappingProfile).Assembly },
configureRegistration: options =>
{
options.ValidateOnStartup = true; // Lanza excepción si hay mapas inválidos
options.PrecompileOnStartup = true; // Compila los mapas inmediatamente
options.ValidationMode = ObjectMappingValidationMode.AllWritableDestinationMembers;
});
2. Crear un Perfil de Mapeo
using Pitasoft.ObjectMapping.Configuration;
public class UserMappingProfile : ObjectMappingProfile
{
public override void Configure(ObjectMappingConfiguration configuration)
{
configuration.CreateMap<UserEntity, UserDto>()
.ToMember(dest => dest.FullName).FromMember(src => $"{src.FirstName} {src.LastName}");
}
}
3. Inyección y Uso
public class UserService(IObjectMapper mapper)
{
public UserDto GetUserDto(UserEntity entity)
{
// Mapeo simple
return mapper.MapTo<UserEntity, UserDto>(entity);
}
}
Autor
Sebastián Martínez Pérez
Licencia
Copyright © 2026 Pitasoft, S.L.
Licenciado bajo los términos de la MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.6)
- Pitasoft.ObjectMapping (>= 1.1.1)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.6)
- Pitasoft.ObjectMapping (>= 1.1.1)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.6)
- Pitasoft.ObjectMapping (>= 1.1.1)
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.0.1 | 182 | 4/17/2026 |