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

작성자

카테고리:

← 피드로
DEV Community · Steven Kamwaza · 2026-07-24 개발(SW)

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

Enter fullscreen mode Exit fullscreen mode

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());
    }
}

Enter fullscreen mode Exit fullscreen mode

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>();
});

Enter fullscreen mode Exit fullscreen mode

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);
    }
}

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

No configuration required.

Automatic Flattening

Nested properties are flattened automatically.

Source

User.Address.City

↓

Destination

UserDto.AddressCity

Enter fullscreen mode Exit fullscreen mode

Nested Object Mapping

Twinify recursively maps nested object graphs.

Order
 └── Customer
 └── Address
 └── Contacts

↓

OrderDto
 └── CustomerDto
 └── AddressDto
 └── ContactDtos

Enter fullscreen mode Exit fullscreen mode

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>();

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

2. Install Twinify

dotnet add package Twinify
dotnet add package Twinify.DependencyInjection

Enter fullscreen mode Exit fullscreen mode

3. Update Your Profiles

Replace

public class UserProfile : Profile

Enter fullscreen mode Exit fullscreen mode

with

public class UserProfile : MappingProfile

Enter fullscreen mode Exit fullscreen mode

4. Update Dependency Injection

Replace

builder.Services.AddAutoMapper(...);

Enter fullscreen mode Exit fullscreen mode

with

builder.Services.AddTwinify(cfg =>
{
    cfg.AddProfile<UserProfile>();
});

Enter fullscreen mode Exit fullscreen mode

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

📦 NuGet

dotnet add package Twinify

Enter fullscreen mode Exit fullscreen mode

📖 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

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다