AutoMapperLite 3.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package AutoMapperLite --version 3.0.1
                    
NuGet\Install-Package AutoMapperLite -Version 3.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="AutoMapperLite" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AutoMapperLite" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AutoMapperLite" />
                    
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 AutoMapperLite --version 3.0.1
                    
#r "nuget: AutoMapperLite, 3.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 AutoMapperLite@3.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=AutoMapperLite&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AutoMapperLite&version=3.0.1
                    
Install as a Cake Tool

AutoMapperLite

A lightweight, customizable object-to-object mapping library for .NET projects.
Designed for internal use in your projects to simplify DTO and entity mapping with easy-to-use profiles, support for nested properties, and flexible configuration.


Features

  • Simple and fast object mapping between source and destination types.
  • Supports nested object mapping.
  • Fluent profile-based configuration similar to AutoMapper.
  • Supports ForMember and ForPath for custom member and nested member mappings.
  • Supports collection mapping (e.g., List<T>).
  • Integration via Dependency Injection (DI).
  • Designed as a small NuGet package for internal project use.

Installation

Install the NuGet package in your project:

dotnet add package AutoMapperLite --version 3.0.1

1. Register AutoMapperLite in your DI container

In your Program.cs or startup configuration:

using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

// Register all profiles from the executing assembly
builder.Services.AddAutoMapperLite(Assembly.GetExecutingAssembly());

var app = builder.Build();

2. Create Mapping Profiles

Define your mappings by creating classes inheriting from Profile and override Configure method:

using AutoMapperLite;
using AutoMapperLite.Interfaces;

public class MyMappingProfile : Profile
{
    public override void Configure(IMapperConfig config)
    {
        // Basic map
        config.CreateMap<Country, CountryViewModel>();

        // Map with ForMember for direct property mapping
        config.CreateMap<Organization, OrganizationViewModel>()
            .ForMember(dest => dest.CountryViewModel, src => src.Country);

        // Map with ForPath for nested properties
        config.CreateMap<Location, LocationViewModel>()
            .ForPath(dest => dest.OrganizationViewModel.CountryViewModel, src => src.Organization.Country);
    }
}

3. Inject and Use Mapper

Inject IMapper in your classes and map objects easily:

public class MyService
{
    private readonly IMapper _mapper;

    public MyService(IMapper mapper)
    {
        _mapper = mapper;
    }

    public LocationViewModel GetLocationViewModel(Location location)
    {
        return _mapper.Map<LocationViewModel>(location);
    }
}

API Overview

CreateMap<TSource, TDestination>()

Defines a mapping between source and destination types.

ForMember(destinationMember, sourceFunc)

Configures mapping for a single direct property of the destination object.

  • destinationMember: Expression to specify a destination property (e.g. dest => dest.CountryViewModel)
  • sourceFunc: Function to select source property/value.

ForPath(destinationPath, sourceFunc)

Configures mapping for nested properties within the destination object.

  • destinationPath: Expression specifying a nested destination property path (e.g. dest => dest.OrganizationViewModel.CountryViewModel.Name)
  • sourceFunc: Function to select source property/value.

When to use ForMember vs ForPath?

ForMember ForPath
Maps a direct, single-level property Maps a nested property several levels deep
Use when destination property is top-level Use when destination has nested complex objects
Simpler and direct Allows mapping into nested objects’ properties

Supported Features

  • Map single objects and collections (List<T>).
  • Auto-mapping properties with the same name and compatible types.
  • Custom member mapping via ForMember and ForPath.
  • Nested object instantiation and mapping.
  • DI-friendly registration with extension method AddAutoMapperLite.
  • Profiles discovery from assemblies.

Folder Structure

AutoMapperLite/
│
├── Core/
│ ├── Mapper.cs # Core mapper logic and reflection
│ ├── MapBuilder.cs # Mapping configuration builder
│ └── Profile.cs # Base Profile class for defining maps
│
├── Interfaces/
│ ├── IMapper.cs # Mapper interface
│ ├── IMapperConfig.cs # Mapper configuration interface
│
├── Extensions/
│ └── ServiceCollectionExtensions.cs # DI extension methods
│
├── README.md # This documentation file
└── AutoMapperLite.csproj # Project file

Contributing

This package is designed for internal or commercial use in your projects.
Feel free to fork, modify, and enhance as needed. Pull requests and suggestions are welcome.


License

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Contact

For questions or help, contact your internal dev team or maintainer. Email: atik.hassan@outlook.com GitHub: AutoMapperLite


Thank you for using AutoMapperLite!
Happy Mapping 😊

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 was computed.  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 was computed.  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.

• Added ForPath and ForMember support
• Improved collection mapping (List<T>)
• Simplified usage with Map<TDestination>(TSource) format
• Support for nested property mapping and configuration profiles
• Refactored internal Mapper logic and added DI support