IronMapper.Extensions.DI 1.1.3

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

IronMapper

NuGet Build License: MIT

📖 Русская документация

Compile-time object mapper for .NET.

IronMapper uses a Roslyn source generator to emit mapping code at build time. The generated MapTo* extension methods are plain C# property assignments: no reflection, no IL emit, no dynamic proxies, and you can step through them in the debugger.

The optional IronMapper.Extensions.DI package adds an IMapper service. It is not reflection-free: it finds the generated methods via reflection and calls them through MethodInfo.Invoke (see Known limitations).


vs AutoMapper

AutoMapper IronMapper
Mapping strategy Mapping plans built at runtime and compiled from expression trees (docs) C# generated at compile time
Configuration errors Reported when you call AssertConfigurationIsValid(), typically in a unit test (docs) Some at build time (IM00xx diagnostics, or C# errors in the generated code); see Known limitations
License 14.x and earlier: MIT. 15.0+: RPL-1.5 or commercial license, with a free Community license for eligible organizations (automapper.io) MIT
API style Profile-based fluent API, [AutoMap] attribute Attributes or profile-based fluent API
ProjectTo for IQueryable Yes Not yet supported (planned, #9)

No performance or package-size numbers are published yet. Benchmarks exist in tests/IronMapper.Benchmarks (manual mapping vs. IronMapper); results will be added to the docs once they are measured and committed.


Quick Start (5 minutes)

1. Install

dotnet add package IronMapper

2. Annotate your source type

using IronMapper.Attributes;

[MapTo(typeof(UserDto))]
public class UserEntity
{
    public int    Id    { get; set; }
    public string Name  { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
}

public class UserDto
{
    public int    Id    { get; set; }
    public string Name  { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
}

3. Map

var entity = new UserEntity { Id = 1, Name = "Alice", Email = "alice@example.com" };
UserDto dto = entity.MapToUserDto();  // generated extension method

That's it. No IMapper and no service registration are needed.


Key Features

Attribute-based mapping

[MapTo(typeof(ProductDto))]      // source → dest
[MapFrom(typeof(ProductEntity))] // dest ← source (equivalent)

Property renaming

[MapProperty("FullName")]
public string Name { get; set; } = "";  // maps to FullName on destination

Ignore properties

[Ignore]
public string InternalSecret { get; set; } = "";

Custom type converters

public class PriceConverter : ITypeConverter<decimal, string>
{
    public string Convert(decimal source) => source.ToString("F2");
}

[MapTo(typeof(InvoiceDto))]
public class Invoice
{
    [MapConverter(typeof(PriceConverter))]
    public decimal Total { get; set; }
}

Profile-based fluent API

public class OrderProfile : MappingProfile
{
    public OrderProfile()
    {
        CreateMap<OrderEntity, OrderDto>()
            .ForMember(d => d.FullAddress, o => o.MapFrom(s => s.Street + ", " + s.City))
            .ForMember(d => d.InternalId,  o => o.Ignore());
    }
}

Collection helpers

List<UserEntity> entities = ...;
List<UserDto>    dtos = entities.MapToUserDtoList();
UserDto[]        arr  = entities.MapToUserDtoArray();

In-place (void) mapping

entity.MapToUserDto(existingDto);  // updates existing object without allocating a new one

Nested collections

[MapTo(typeof(BlogDto))]
public class BlogEntity
{
    public List<CommentEntity> Comments { get; set; } = new();
}
// generator emits: Comments = source.Comments is null ? null! : Enumerable.ToList(Enumerable.Select(source.Comments, x => x.MapToCommentDto()))

Requires a mapping CommentEntity → CommentDto. Only List<T> → List<TDto> is covered by tests. Nested single objects are not mapped automatically, see Known limitations.

ASP.NET Core DI

// Program.cs — registers IMapper and the MappingProfile types from the assembly
builder.Services.AddIronMapper(typeof(Program).Assembly);

// In a controller / service
public class OrdersController(IMapper mapper) : ControllerBase
{
    public OrderDto Get(int id) => mapper.Map<OrderDto>(_repo.GetById(id));
}

Demo Application

A sample console app shows the main IronMapper features using the real Open Library API (no API key required).

What the demo covers:

  • Simple attribute-based mapping ([MapTo])
  • Fluent API with MappingProfile
  • Collection mapping (List<BookDoc> → List<BookSummary>)
  • Nested objects (book and author mapped separately, then combined in code)
  • Custom type converters (HTML bio cleaner)
  • Conditional mapping (living authors only)

Run it:

git clone https://github.com/iron-mapper/IronMapper
cd IronMapper
dotnet run --project samples/IronMapper.Demo

Known limitations

Current gaps, confirmed by reading the code. Each one is either planned or tracked in an issue.

  • Nested single objects are not mapped automatically. For Customer.Address → CustomerDto.Address with different types the generator emits Address = source.Address, and the build fails with CS0029 in the generated file. Workaround: ForMember(d => d.Address, o => o.MapFrom(s => s.Address.MapToAddressDto())). Nested collections are handled (see above).
  • Private and protected nested types cannot be mapped. Generated methods live in the top-level class IronMapper.Generated.GeneratedMappers, which cannot see private, protected or private protected nested types. Such a mapping is reported as IM0010 and skipped; the other mappings are still generated. Internal types are supported: the generated methods are then internal (see Generated method accessibility).
  • Multi-project solutions: every project declares its own IronMapper.Generated.GeneratedMappers (internal when all its mappings are internal). Call mappings of other projects as extension methods (source.MapToX()); naming the class explicitly reports CS0436 when a referenced project's class is visible, and mapping the same type pair in two projects makes source.MapToX() ambiguous (CS0121). See Multi-project solutions.
  • Positional records as destinations do not compile (CS7036): the generator always uses an object initializer. Records and classes with init properties work.
  • Incompatible property types are not diagnosed. IM0002, IM0003 and IM0004 are declared but never reported; the build fails later with a C# error in the generated file. See diagnostics.
  • Same-named destination types get qualified method names. Mapping one source type to two destination types with the same simple name (e.g. Admin.UserDto and Public.UserDto) generates MapToAdminUserDto/MapToPublicUserDto instead of MapToUserDto (IM0013); adding such a second type later renames the existing method. A type pair defined twice is generated once (IM0007, the profile wins). See Method names and collisions.
  • Profile mappings get fewer diagnostics. IM0001 and IM0009 are reported only for [MapTo]/[MapFrom]; unmatched destination properties in profiles are skipped silently. All diagnostics are reported without a source location.
  • The in-place overload source.MapToX(existing) ignores When, ConvertUsing, BeforeMap/AfterMap and skips init properties.
  • ReverseMap() maps by property name only; ForMember, When, hooks and IncludeMembers are not reversed.
  • Profile lambdas are rewritten into the generated class with fully qualified names (extension methods become static calls). They cannot use instance members of the profile, this or locals of the constructor (IM0012), nor private/protected members — make those internal (IM0011). Extension methods called after ?. are emitted unchanged. See Profile lambdas.
  • Converters are created with new TConverter() (a public parameterless constructor is required). IronMapperOptions.AddConverter<T>() only registers the type in DI; generated code does not use it.
  • IMapper (IronMapper.Extensions.DI) uses reflection: it scans loaded assemblies, matches methods by destination type name and exact runtime source type, and calls them via MethodInfo.Invoke. Map<List<TDto>>(list) throws MappingException (#8); there is no per-call context (#7).
  • ProjectTo / IQueryable projection is not supported yet (planned, #9).
  • NativeAOT / trimming has not been verified. The generated extension methods contain no reflection; IMapper relies on reflection and should be treated as incompatible.
  • Platforms. Packages target netstandard2.0 + net10.0 (IronMapper) and netstandard2.1 + net10.0 (IronMapper.Extensions.DI). Tests run only on .NET 10 (Ubuntu and Windows in CI); other runtimes are not tested. The generator is built against Microsoft.CodeAnalysis 4.11.
  • The IM0001/IM0006 code fixes have no tests.

Documentation


Contributing

Contributions are welcome! Please:

  1. Fork the repo and create a feature branch (feature/my-feature).
  2. Make your changes with tests.
  3. Run dotnet build and dotnet test — both must be clean.
  4. Open a pull request against main.

Please follow the existing code style (see .editorconfig).


License

MIT © 2026 Aleksey Mironov

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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 was computed.  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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
2.0.0 180 10/23/2026
1.1.4 107 10/20/2026
1.1.3 146 10/18/2026
1.1.2 103 10/18/2026
1.1.1 115 10/17/2026
1.1.0 171 4/7/2026
1.0.0 132 4/2/2026