AutoMapperLite 4.4.0
See the version list below for details.
dotnet add package AutoMapperLite --version 4.4.0
NuGet\Install-Package AutoMapperLite -Version 4.4.0
<PackageReference Include="AutoMapperLite" Version="4.4.0" />
<PackageVersion Include="AutoMapperLite" Version="4.4.0" />
<PackageReference Include="AutoMapperLite" />
paket add AutoMapperLite --version 4.4.0
#r "nuget: AutoMapperLite, 4.4.0"
#:package AutoMapperLite@4.4.0
#addin nuget:?package=AutoMapperLite&version=4.4.0
#tool nuget:?package=AutoMapperLite&version=4.4.0
<p align="center"> <picture> <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.png"> <img src="docs/assets/logo-light.png" alt="AutoMapperLite" width="360"> </picture> </p>
<p align="center"> <strong>v4.4.0</strong> · <a href="LICENSE">MIT License</a> · net6.0 – net10.0 · <a href="https://automapperlite.atkhssn.info">automapperlite.atkhssn.info</a> </p>
AutoMapperLite
A lightweight, customizable object-to-object mapping library for .NET projects. Designed to simplify DTO and entity mapping with easy-to-use profiles, support for nested properties, and flexible configuration — created and maintained by Atik Hassan.
Targets net6.0, net7.0, net8.0, net9.0, and net10.0.
4.4.0 is the current official release. All prior versions (4.0.2 and earlier) are deprecated — see CHANGELOG.md for release history.
📖 Full documentation (Getting Started, API reference, usage guide, performance, FAQ, comparison): automapperlite.atkhssn.info.
Features
- Simple, lightweight object mapping between source and destination types.
- Supports nested object mapping, including nested
List<T>properties whose item types have a registered map. - Fluent profile-based configuration similar to AutoMapper.
- Supports
ForMemberandForPathfor custom member and nested member mappings. - Supports collection mapping to
List<T>, arrays, and common collection interfaces (IList<T>,ICollection<T>,IReadOnlyList<T>,IReadOnlyCollection<T>,IEnumerable<T>). - Integration via Dependency Injection (DI) —
IMapperConfigandIMapperare both registered as singletons, since neither holds per-request state. - Thread-safe: mapping configuration and the mapper itself can be used concurrently.
- Designed as a small NuGet package for internal project use.
Installation
Install the NuGet package in your project:
dotnet add package AutoMapperLite --version 4.4.0
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>();
// ForMember/ForPath functions must return the already-mapped value, not the raw
// source sub-object — the library does not implicitly convert types for you. When
// the source and destination property types differ (as here: Country vs.
// CountryViewModel), map through the mapper itself inside the function.
var mapper = new Mapper(config);
// Map with ForMember for direct property mapping
config.CreateMap<Organization, OrganizationViewModel>()
.ForMember(dest => dest.CountryViewModel, src => mapper.Map<CountryViewModel>(src.Country));
// Map with ForPath for nested properties
config.CreateMap<Location, LocationViewModel>()
.ForPath(dest => dest.OrganizationViewModel.CountryViewModel, src => mapper.Map<CountryViewModel>(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>, arrays,IList<T>,ICollection<T>,IReadOnlyList<T>,IReadOnlyCollection<T>,IEnumerable<T>). - Auto-mapping properties with the same name and compatible types.
- Custom member mapping via
ForMemberandForPath. - 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
│ └── MapperConfig.cs # Mapping registry (CreateMap / GetMap / HasMap)
│
├── Mapping/
│ ├── MapBuilder.cs # Fluent mapping configuration builder (ForMember / ForPath)
│ └── Profile.cs # Base Profile class for defining maps
│
├── Interfaces/
│ ├── IMapper.cs # Mapper interface
│ └── IMapperConfig.cs # Mapper configuration interface
│
├── Extensions/
│ └── ServiceCollectionExtensions.cs # DI extension methods
│
├── AutoMapperLite.Tests/ # xUnit test project
├── AutoMapperLite.Benchmarks/ # BenchmarkDotNet benchmark project
├── docs/ # Static documentation site (deploys to automapperlite.atkhssn.info)
│
├── README.md # This documentation file
├── CHANGELOG.md # Release history
├── LICENSE # MIT License
├── CONTRIBUTING.md # Contribution guidelines
├── CODE_OF_CONDUCT.md # Contributor Covenant
├── SECURITY.md # Vulnerability reporting policy
└── AutoMapperLite.csproj # Library 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 — see CONTRIBUTING.md for how to get started, and CODE_OF_CONDUCT.md for community expectations.
For reporting security vulnerabilities, see SECURITY.md.
License
AutoMapper Lite is open-source software licensed under the MIT License.
You are free to use, modify, distribute, and use this software commercially, subject to the conditions of the MIT License.
Frequently Asked Questions
Is AutoMapperLite free and open source? Yes — MIT licensed, free for personal and commercial use. See License.
Which .NET versions are supported? net6.0, net7.0, net8.0, net9.0, and net10.0.
Is it thread-safe? Yes — configuration (CreateMap) and mapping (Map) can both be used concurrently; see the concurrency tests in AutoMapperLite.Tests.
How does it compare to AutoMapper or Mapster? AutoMapperLite is intentionally smaller in scope — no LINQ projection support, no convention/coercion engine, just CreateMap/ForMember/ForPath compiled into cached delegates per type pair. Choose it when you want a minimal-dependency mapper for straightforward DTO/entity mapping; choose AutoMapper or Mapster for large projects needing LINQ ProjectTo, value converters, or maximum raw throughput — see the real, measured comparison.
More questions answered in the full FAQ.
Contact
Project: AutoMapperLite · GitHub
Author: Atik Hassan · atik.hassan@outlook.com
Thank you for using AutoMapperLite! Happy Mapping 😊
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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
-
net6.0
-
net7.0
-
net8.0
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
AutoMapperLite 4.4.0 — current official release; all prior versions are deprecated.
Mapping engine and performance redesign. Each source/destination type pair now
compiles into a cached delegate via System.Linq.Expressions on first use, instead of
interpreting mappings through reflection. Dispatch, collection element resolution, and
nested same-name property mapping are all resolved once and cached rather than
re-resolved per call. See docs/performance.html for full measured results.
• Added: IMapper.Map<TSource, TDestination>(TSource source) — a strongly-typed
overload for call sites where the source type is known at compile time. This is the
fastest way to call AutoMapperLite, and now also works directly for collections:
mapper.Map<List<TSourceItem>, List<TDestItem>>(sourceList) skips resolving
the source collection's runtime type.
• Added: collection destinations are no longer limited to List<T>.
Map<TDestination>(object) now also accepts T[], IList<T>, ICollection<T>,
IReadOnlyList<T>, IReadOnlyCollection<T>, and IEnumerable<T>. The same
flexibility applies to same-name nested collection properties.
• Performance: fixed a collection-loop interface-dispatch cost that was limiting
collection-mapping throughput — casting the source to IEnumerable<T> and using
foreach forced List<T>'s own struct enumerator to be boxed through the interface on
every call. The loop now indexes List<T>/arrays directly. Measured: a 100-item
collection dropped from ~1.3 us to ~0.78 us (object API) / ~0.67 us (generic API); a
5,000-item collection dropped from ~60-74 us to ~35 us. AutoMapperLite now beats
AutoMapper on collection mapping at every size from 1,000 items upward (previously it
trailed), and at 100,000 items is within 8% of hand-written manual mapping's own time.
• Behavior change (disclosed): exceptions raised during mapping now propagate directly
as InvalidOperationException instead of being wrapped in TargetInvocationException.
• Behavior change (disclosed): List<T> mapping resolves the item map from the source
collection's declared item type rather than each element's runtime type.
• Allocations for simple, medium, nested, and deeply-nested object mapping now match
hand-written manual mapping exactly. Collection mapping allocation now matches manual
mapping/Mapster exactly via the generic API, from 10 items to 100,000.
• No public API breaking changes since 4.0.2 (only for anyone implementing IMapper
directly rather than using the built-in Mapper class, due to the new interface
member above).
Previous (4.0.2):
• Fixed: updated test tooling required net8.0+; the test project now targets
net8.0-net10.0 (the library itself still targets net6.0-net10.0).
• Fixed: Activator.CreateInstance failures now throw a clear InvalidOperationException
naming the type, instead of a bare MissingMethodException.
• Added real, measured BenchmarkDotNet comparisons against manual mapping, AutoMapper,
and Mapster.
• Verified and documented: null source properties are skipped (not assigned), auto-map
requires an exact type match, and records with init-only properties map correctly.