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
                    
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="Pitasoft.ObjectMapping.DependencyInjectionExtensions" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pitasoft.ObjectMapping.DependencyInjectionExtensions" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Pitasoft.ObjectMapping.DependencyInjectionExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pitasoft.ObjectMapping.DependencyInjectionExtensions --version 1.0.1
                    
#r "nuget: Pitasoft.ObjectMapping.DependencyInjectionExtensions, 1.0.1"
                    
#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.
#:package Pitasoft.ObjectMapping.DependencyInjectionExtensions@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pitasoft.ObjectMapping.DependencyInjectionExtensions&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Pitasoft.ObjectMapping.DependencyInjectionExtensions&version=1.0.1
                    
Install as a Cake Tool

Pitasoft.ObjectMapping.DependencyInjectionExtensions

NuGet Version NuGet Downloads License .NET Built with Pitasoft.ObjectMapping

English | Castellano


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 IObjectMapper and ObjectMappingConfiguration as singletons.
  • Profile Discovery: Automatically scans assemblies to find and register your ObjectMappingProfile classes.
  • 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 IObjectMapper y ObjectMappingConfiguration como 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 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. 
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.0.1 182 4/17/2026