IronMapper.Extensions.DI
1.1.3
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
<PackageReference Include="IronMapper.Extensions.DI" Version="1.1.3" />
<PackageVersion Include="IronMapper.Extensions.DI" Version="1.1.3" />
<PackageReference Include="IronMapper.Extensions.DI" />
paket add IronMapper.Extensions.DI --version 1.1.3
#r "nuget: IronMapper.Extensions.DI, 1.1.3"
#:package IronMapper.Extensions.DI@1.1.3
#addin nuget:?package=IronMapper.Extensions.DI&version=1.1.3
#tool nuget:?package=IronMapper.Extensions.DI&version=1.1.3
IronMapper
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.Addresswith different types the generator emitsAddress = source.Address, and the build fails withCS0029in 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 seeprivate,protectedorprivate protectednested types. Such a mapping is reported asIM0010and skipped; the other mappings are still generated. Internal types are supported: the generated methods are theninternal(see Generated method accessibility). - Multi-project solutions: every project declares its own
IronMapper.Generated.GeneratedMappers(internalwhen all its mappings are internal). Call mappings of other projects as extension methods (source.MapToX()); naming the class explicitly reportsCS0436when a referenced project's class is visible, and mapping the same type pair in two projects makessource.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 withinitproperties work. - Incompatible property types are not diagnosed.
IM0002,IM0003andIM0004are 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.UserDtoandPublic.UserDto) generatesMapToAdminUserDto/MapToPublicUserDtoinstead ofMapToUserDto(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.
IM0001andIM0009are 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)ignoresWhen,ConvertUsing,BeforeMap/AfterMapand skipsinitproperties. ReverseMap()maps by property name only;ForMember,When, hooks andIncludeMembersare 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,
thisor locals of the constructor (IM0012), norprivate/protectedmembers — make thoseinternal(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 viaMethodInfo.Invoke.Map<List<TDto>>(list)throwsMappingException(#8); there is no per-call context (#7).ProjectTo/IQueryableprojection is not supported yet (planned, #9).- NativeAOT / trimming has not been verified. The generated extension methods contain no reflection;
IMapperrelies on reflection and should be treated as incompatible. - Platforms. Packages target
netstandard2.0+net10.0(IronMapper) andnetstandard2.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
- Getting Started
- Configuration Reference
- Advanced Topics
- Migrating from AutoMapper
- Compiler Diagnostics
Contributing
Contributions are welcome! Please:
- Fork the repo and create a feature branch (
feature/my-feature). - Make your changes with tests.
- Run
dotnet buildanddotnet test— both must be clean. - Open a pull request against
main.
Please follow the existing code style (see .editorconfig).
License
MIT © 2026 Aleksey Mironov
| Product | Versions 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. |
-
.NETStandard 2.1
- IronMapper (>= 1.1.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
-
net10.0
- IronMapper (>= 1.1.3)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.