Getting Started with Twinify: A Free, Open-Source Object Mapper for Modern .NET
DEV Community

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:

  • CreateMap
  • ForMember
  • MapFrom
  • Ignore
  • Condition
  • ConvertUsing
  • BeforeMap
  • AfterMap
  • ReverseMap
  • IncludeBase
  • PreserveReferences

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

  1. Remove AutoMapper

    dotnet remove package AutoMapper
    
  2. Install Twinify

    dotnet add package Twinify
    dotnet add package Twinify.DependencyInjection
    
  3. Update Your Profiles

    Replace public class UserProfile : Profile with public class UserProfile : MappingProfile.

  4. Update Dependency Injection

    Replace builder.Services.AddAutoMapper(...); with:

    builder.Services.AddTwinify(cfg =>
    {
        cfg.AddProfile<UserProfile>();
    });
    
  5. Build & Test

    Many existing CreateMap() and ForMember() 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

โญ 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.