The Best .NET Mapper to Use in 2023

preview_player
Показать описание

Hello everybody I'm Nick and in this video I will compare all the .NET Object Mappers to see which one is the best and which one you should choose. I tested Automapper, AgileMapper, TinyMapper, Mapster, MappingGenerator, Mapperly and also manual mapping to see how they compare.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet
Рекомендации по теме
Комментарии
Автор

Mapperly has the benefits of not hiding references behind reflection, build time errors, speed, etc. and simplicity if you want to remove it later (can just copy the generated code out and remove the mapper).

Автор

Thx for comparison. I prefer writing mapper as extension method (outside of domain). Simple and dependency free only when I have a lot of mapping I'm thinking of using mapper. Mapperly looks interesting.

marcinz
Автор

I honestly prefer to just have a static function in the class that takes in model and returns the transfer model or vice versa it’s faster, easier to debug, easier to understand for people not familiar with your mapper of choice and requires 0 extra dependencies. It’s also removes the temptation of doing conversions in the mapper function itself which are just horrific to debug when something you didn’t write isn’t behaving as you expect, because some “clever” conversion is being done hidden away in the mapper. Too many bad memories for me to ever use a mapper

justgame
Автор

Greetings Nick. I use AutoMapper. Mapperly seems like a better choice.

AutoMapper reduced the amount of code in the project, but it also tends to get complicated as soon as you deviate from base implementations. I found myself adding an extension method in some cases to tidy up initialization. One example is where mapping requires two different source objects.

CodySkidmorenh
Автор

Thank you for this. I've always created my own custom mapper but am going to implement Mapperly in my current project.

DanBryant-hg
Автор

Most of the time I prefer manual mapping. I developed an also fast but very simplistic mapping library called hypercubus mapping which is based on that (just need to finish the test cases to open source it). It keeps some useful concepts behind mapping: the ability to separate mapping concerns into another layer, creation of profiles, automatic enumerable types handling and the reusability of mapping rules. I also like to put its usage behind an interface owned by each application so that it can be easily changed as the project develops. So if time is short we can start using Mapster with naming conventions and then move to hand written code later with hypercubus or the even faster Mapperly

danilonotsys
Автор

In my experience about 30% of the time you need custom configutations in the mapping. Excluding properties, converting comma separated values to List, creating nested objects from several DTO properties, etc.
So I would love to see a comparison between these mappers in how easy-to-use are they in custom configurations.

sergeybenzenko
Автор

I have been using AutoMapper for a long time now. I think I started using it back in the days of the static API.
HOWEVER, I have reached a point where I am prepared to dump AutoMapper as the maintainers of the source do not write very good documentation to explain certain things and even have gone so far as to just outright delete a question they didn’t like, saying it should be answered on Stack Overflow instead, which is just dumb when I was asking them for clarification on a point in their documentation related to breaking changes they introduced in version 12 that are poorly explained. One thing I will say is that they have a great method you can call in your application startup when you are configuring your mapper. After you have registered all of your maps, you can call the AssetConfigurationIsValid method. This ensures you don’t have any properties added after the fact that can’t be mapped or are missed. Very good thing to have, especially in your development environment.
All that being said, I am going to be looking closely at Mapperly to see if I can swap out AutoMapper for it. I admit I have included some business logic in my mappings in some limited places. I am going to be reassessing that approach in the future.

stephajn
Автор

I used to write my own mappings but that got laborious quickly so I switched about 5 years ago to Automapper. I've always found it ok but my biggest frustration with it though is it doesn't tell you when it's not going to work, it'll build with mapping errors etc. Mapperly looks good so I'm going to take a look at that one now. Thanks for the video, very useful.

markharwood
Автор

Mapping makes absolutely sense when you have a rich domain model in your application core, however, in the "outer layers" you need simple objects (DTOs mainly).

krccmsitp
Автор

I used to go with automapper but then change for mapster which is way faster .... did not know about mapperly, i'll give it a try .... Thanks for that great insight on mapping tools

netgeek
Автор

Thanks. I’ll try it. I mainly use mappers to hide the DTOs returned by web services or mapping something to a view model.

chrismcisaac
Автор

It's really funny how I made a research on mappers today and I come back home to this video notification.

I handle mapping myself but I needed to find a way to focus on implementing functionality and worry less about mapping object.

Thank you for this video Nick, it has cleared up a few gray areas and helped me to focus my research. I'll still take on your advice to handle mapping myself where need be. That is a safer bet.

ikenwakochukwudi
Автор

I did not know about mapperly, I use manual mapping, gonna give it a try on my next prject, thanks for sharing!

guillermomazzari
Автор

My favorite mapper now is manual mapping written by ChatGPT 💯

Just make it write the tedious parts, then wire in the more complicated ones ourselves.

conway
Автор

Thank you for showing me Maperly. I never liked runtime mapping and I never found any source generated mapper the last time I looked few months ago. I'm definitely going to try it out.

ekeke
Автор

Decided to try mapperly following this video. I've always tended to write my own mappers rather than using something like Automapper in the past so it is my first foray into automated mappers. Unfortunately, it doesn't look like it supports doing something like this from what I see on the website where you have a generic type within both the DTO and the model and want to define that at the point you are mapping:


public partial class MapperlyMapper

{
public partial Email<T> Map(EmailDto<T> sendEmailDto);
}

public class Email<T>
{
public T Message {get; set;}
}

public class EmailDto<T>
{
public T Message {get; set;}
}

JasonEspin
Автор

I see few issues based on my deep dive in that problem:
1. Performance difference of mapping of an array with 100 items of small entities vs just few objects with complicated structures. I saw tests where simpler objects got mapped faster by one, while more complicated by the other one.
2. Use of projections. EFCore, Mongo, CosmosDb all take advantage from that. If you use map functions shown here all those will have to first download everything and then map, and then filter! I see this issue so commonly misunderstood. People get the fastest mapper to suffer even more than before.
3. Functionality. I can feed arrays or dictionaries of my classes to AutoMapper directly and it will convert it properly in one call. Ability to provide context, transformation functions, etc. ability to restructure objects (source has deep nested structure converting to flat object), ability to lookup values in another collection, and so on.

igorsolomatov
Автор

Mapperly looks awesome, as performant as manual code without having to type much

Will be using that going forward, thanks Nick!

frotes
Автор

I need more documentation about Mapperly! Using the mapper for generating new data types, fill a dashboard dto, etc.

jose-sebastian-garcia