IronMapper.Extensions.DI
1.1.0
dotnet add package IronMapper.Extensions.DI --version 1.1.0
NuGet\Install-Package IronMapper.Extensions.DI -Version 1.1.0
<PackageReference Include="IronMapper.Extensions.DI" Version="1.1.0" />
<PackageVersion Include="IronMapper.Extensions.DI" Version="1.1.0" />
<PackageReference Include="IronMapper.Extensions.DI" />
paket add IronMapper.Extensions.DI --version 1.1.0
#r "nuget: IronMapper.Extensions.DI, 1.1.0"
#:package IronMapper.Extensions.DI@1.1.0
#addin nuget:?package=IronMapper.Extensions.DI&version=1.1.0
#tool nuget:?package=IronMapper.Extensions.DI&version=1.1.0
IronMapper
Zero-reflection, compile-time object mapper for .NET.
IronMapper generates all mapping code at build time using a Roslyn Source Generator — no runtime reflection, no IL emit, no dynamic proxies. Just plain, readable, debuggable C# that the compiler can optimize like any other code.
vs AutoMapper
| Feature | AutoMapper | IronMapper |
|---|---|---|
| Mapping strategy | Reflection at runtime | Source-generated C# at compile time |
| Misconfiguration detected | At app startup | At dotnet build |
| NativeAOT / IL trimming | Requires annotations | Fully compatible |
| Performance | ~2–5 µs / object | ~0 ns overhead |
| License | MIT | MIT |
| API style | Profile-based fluent API | Attributes or Profile-based fluent API |
| Package size | ~500 KB | ~30 KB |
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, no service registration, no startup overhead.
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 = Enumerable.ToList(Enumerable.Select(source.Comments, x => x.MapToCommentDto()))
ASP.NET Core DI
// Program.cs
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
We've built a sample console app that showcases all 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 object mapping (Book + Author)
- 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
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 © Iron Programmer School
| 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.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
-
net10.0
- IronMapper (>= 1.1.0)
- 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.