Getting Started with Twinify: A Free, Open-Source Object Mapper for Modern .NET
Lightweight. Familiar. MIT Licensed. Built for .NET 8, 9, and 10.
Following AutoMapper's recent licensing changes, many .NET developers have started looking for an open-source alternative that doesn't require rewriting years of mapping code. That's one of the reasons I built Twinify. Twinify is a lightweight, high-performance object-to-object mapper that provides a familiar fluent API, making it easy to map DTOs, entities, view models, records, and complex object graphs while remaining completely open source under the MIT License. If you're already using AutoMapper, you'll find the transition straightforward for many common mapping scenarios.
Why Twinify?
- โ MIT Licensed
- โ Built for .NET 8, .NET 9 & .NET 10
- โ Familiar AutoMapper-style Fluent API
- โ Dependency Injection Support
- โ Automatic Convention-Based Mapping
- โ Nested Objects & Collections
- โ Flattening
- โ Record & Constructor Mapping
- โ Mapping Diagnostics with
Explain<TSource, TDestination>()
Installation
Install the required packages:
dotnet add package Twinify
dotnet add package Twinify.DependencyInjection
Step 1 - Create a Mapping Profile
Define your mappings by inheriting from MappingProfile.
public class UserProfile : MappingProfile
{
public UserProfile()
{
CreateMap<User, UserDto>()
.ForMember(d => d.FullName, opt => opt.MapFrom(s => $"{s.FirstName} {s.LastName}"))
.ForMember(d => d.Password, opt => opt.Ignore());
}
}
Twinify uses a familiar fluent configuration model that should feel natural to developers coming from AutoMapper.
Step 2 - Register Twinify
Register your mapping profiles during application startup.
builder.Services.AddTwinify(cfg =>
{
cfg.AddProfile<UserProfile>();
});
Step 3 - Map Your Objects
Inject IMapper wherever it's needed.
public class UserService(IMapper mapper)
{
public UserDto GetUser(User user)
{
return mapper.Map<UserDto>(user);
}
}
That's all you need. Twinify automatically maps properties with matching names while allowing full customization when required.
Features
Automatic Convention Mapping
Properties with identical names are mapped automatically.
User.Name
โ
UserDto.Name
No configuration required.
Automatic Flattening
Nested properties are flattened automatically.
Source User.Address.City
โ
Destination UserDto.AddressCity
Nested Object Mapping
Twinify recursively maps nested object graphs.
Order
โโโ Customer
โโโ Address
โโโ Contacts
โ
OrderDto
โโโ CustomerDto
โโโ AddressDto
โโโ ContactDtos
Collection Mapping
Supports:
- Lists
- Arrays
- Dictionaries
- Nested collections
Constructor & Record Mapping
Twinify automatically constructs destination types, including:
- Immutable objects
- Records
- Parameterized constructors
Fluent Configuration
Twinify supports a rich configuration API, including:
CreateMapForMemberMapFromIgnoreConditionConvertUsingBeforeMapAfterMapReverseMapIncludeBasePreserveReferences
Explain Your Mappings
One feature that sets Twinify apart is mapping diagnostics.
mapper.Explain<User, UserDto>();
Instead of guessing why a property mapped the way it did, Explain() shows exactly where every destination member receives its value, making debugging significantly easier.
Migrating from AutoMapper
Many existing AutoMapper projects can migrate with only a few mechanical changes.
| AutoMapper | Twinify |
|---|---|
Profile |
MappingProfile |
CreateMap() |
Same familiar API |
ForMember() |
Same familiar API |
MapFrom() |
Same familiar API |
ReverseMap() |
Supported |
AddAutoMapper() |
AddTwinify() |
| Custom resolvers | ConvertUsing() and member configuration |
Migration Guide
Remove AutoMapper
dotnet remove package AutoMapperInstall Twinify
dotnet add package Twinify dotnet add package Twinify.DependencyInjectionUpdate Your Profiles
Replace
public class UserProfile : Profilewithpublic class UserProfile : MappingProfile.Update Dependency Injection
Replace
builder.Services.AddAutoMapper(...);with:builder.Services.AddTwinify(cfg => { cfg.AddProfile<UserProfile>(); });Build & Test
Many existing
CreateMap()andForMember()configurations should require little or no modification. As with any migration, it's recommended to run your existing mapping tests to validate behavior.
Why I Built Twinify
I wanted a mapper that is:
- Open source
- Lightweight
- Easy to understand
- Familiar to existing AutoMapper users
- Built specifically for modern .NET
Rather than forcing developers to learn an entirely new API, Twinify focuses on keeping the transition intuitive while continuing to evolve with community feedback.
Getting Started
- ๐ฆ NuGet:
dotnet add package Twinify - ๐ Documentation: https://github.com/StevenKamwaza/Twinify.Docs
- ๐ป Source Code: https://github.com/StevenKamwaza/Twinify
โญ If Twinify helps your project, consider giving the repository a star and sharing your feedback. Community contributions and feature requests are always welcome.
Happy Coding! ๐ Built with โค๏ธ for the .NET community.
Share Your Thoughts
Have questions, feature ideas, or migration feedback? Open an issue or start a discussion on GitHub-I'd love to hear how you're using Twinify in your projects.
Trending Hashtags
#dotnet #csharp #dotnet8 #dotnet9 #dotnet10 #opensource #nuget #softwareengineering #backend #webdevelopment #cleanarchitecture #developer #coding #programming #github #aspnetcore #entityframework #architecture #productivity #developers #devcommunity #100DaysOfCode #BuildInPublic #OSS #AutoMapper #Twinify
Comments
No comments yet. Start the discussion.