The Best .NET Mapper to Use in 2023

The Best .NET Mapper to Use in 2023

Nick Chapsas

1 год назад

89,916 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@marcelotieghi936
@marcelotieghi936 - 30.11.2023 03:57

I am new to this area, so let me ask: Are DTOs the same as View Models? Or do they have different objectives? I've tried searching, but it's getting more confusing. Some say they are similar, while others claim that their purposes are distinct

Ответить
@Sergio_Loureiro
@Sergio_Loureiro - 09.11.2023 13:13

In Mapperly how do you do simple tweaking?
For example, imagine I have a boolean on the model, and a {"Yes", "No"} string on the viewmodel. This is very easy to do on AutoMapper. But where are the entry points on Mapperly to allow to do this and how to do it?

Ответить
@jose-sebastian-garcia
@jose-sebastian-garcia - 07.11.2023 06:06

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

Ответить
@danielschmid8530
@danielschmid8530 - 31.10.2023 13:21

If I'm not supposed to make database calls in the mapper then how am I supposed to resolve lookups?
Let's say System A has a table of users with unique email addresses. System B has a list of users where the email address is unique, but there is a user ID column in the table which the API requires me to use to reference the desired user. I have to resolve the user by the email address. Where would this transformation logic go?

Ответить
@joaocardoso8580
@joaocardoso8580 - 28.10.2023 12:08

Been trying to use mapperly but kinda got stuck on the circular dependencies, even with their annotation, my case seems to be more complex with some methods using a custom mapping and others not :/

Ответить
@JasonEspin
@JasonEspin - 18.10.2023 16:11

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

Ответить
@metalor696
@metalor696 - 27.09.2023 21:31

Ive only used automapper and holy shit I hate it 😊

Ответить
@qlee50
@qlee50 - 27.09.2023 17:32

I’m less concerned with mapping speed and more concerned with things like is it type strict (nullable vs non nullable) or will it do some intelligent cast/conversion

Ответить
@user-hh7cy8tr6h
@user-hh7cy8tr6h - 23.09.2023 21:30

I don't know why byt in my laptop Generated_Map is 723ns and ManualMapper is 366ns.... AutoMapper is not running at all )
I wrote code from video, not your repo.

Ответить
@user-hh7cy8tr6h
@user-hh7cy8tr6h - 23.09.2023 05:00

Mapping generator avaliable only in paid version... sad

Ответить
@markharwood6794
@markharwood6794 - 18.09.2023 16:22

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.

Ответить
@Isr5d
@Isr5d - 17.09.2023 21:02

Mapperly is new to me, and I was surprised by its results. I think it'll be my next mapping pet😎.

Ответить
@Sokak91
@Sokak91 - 23.08.2023 02:13

Definitely an interesting comparison. I have been using Automapper for yonks but have been considering alternatives to see what is out there that might be easier to set up yet still support everything I do. I have been considering Mapster for a while and will have a look at Mapperly.. I'm honestly not a fan of code generation as it tends to muck up things like getting it excluded from code coverage. Though I'm less of a fan of things like convention-based / reflection, so in my case it's a lesser of two evils. Ease of explicit configuration is important to me because often I am flattening things like entity graphs, and want to ignore some values that will end up being loaded as references. I am also looking at details like support for projection, so integrating into things like Entity Framework and it's IQueryable implementation.

Ответить
@drndn
@drndn - 17.08.2023 14:29

Does not Entity Framework count as a mapper? Why not include it in the options?

Ответить
@ldelossantos
@ldelossantos - 07.07.2023 23:00

if you can use automapper, you have an useless layer.

Ответить
@stephajn
@stephajn - 09.06.2023 04:47

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.

Ответить
@Benke01
@Benke01 - 31.05.2023 22:15

I don't agree with the statement that the fastest mapper is the best mapper. 🤔Instead of chasing nanoseconds their features, how configurations are setup and how easy they are to work with is more valuable. Mapping a DB entity to a DTO is mostly quite simple. Their disadvantages can show when you want to map the other way around; from a DTO (or child DTO) to a DB entity, especially in the case of EF Core if that entity is already being tracked.

Ответить
@jonb8869
@jonb8869 - 19.05.2023 20:24

Take your mapper and put it in the trash. Thank you goodbye.

Ответить
@Mr767267
@Mr767267 - 15.05.2023 15:24

Mapperly definitely looks great. How can a change in DTO be reflected using Mapperly, will it auto update the generated code while I re-build?

Ответить
@troepolik
@troepolik - 13.05.2023 09:39

Mapster also has source generated version.

Ответить
@garcipat
@garcipat - 09.05.2023 20:45

In our project we map manually between db => bl => api because the dto can look different or sometimes we have different dtos, penending if an object is in a list or a detailed view. Also mapping from bl => db we want to update an entity, not creating a new one. Those are som reasons why manual mapping is required in our case.

Ответить
@edwardfyodorov8268
@edwardfyodorov8268 - 09.05.2023 16:01

I use my custom mappers :))

Ответить
@frotes
@frotes - 09.05.2023 01:27

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

Will be using that going forward, thanks Nick!

Ответить
@parlor3115
@parlor3115 - 02.05.2023 22:32

@Nick Are you really ok with using random libraries in your enterprise software? It doesn't sit well with me that I could be using a package that may as well contain code that would give my entire database to some Nigerian prince or delete "/". And I'm not even refering to obscure packages either. I don't think even popular projects like MediatR or Dapper can be said to be 100% safe.

Ответить
@rookieew
@rookieew - 26.04.2023 01:26

Mapper are for Millennials+ and lazy people 😂

Ответить
@Gab-ub2pw
@Gab-ub2pw - 24.04.2023 12:38

I am relativly new to that mapping issue: what about explicit and implicit operators and their performance? Shouldn't be they mentioned as well here?

Ответить
@Gab-ub2pw
@Gab-ub2pw - 24.04.2023 12:05

@Nick: Do you have a video about writing your own mapper?

Ответить
@DummyFace123
@DummyFace123 - 23.04.2023 02:08

Honestly if mapperly could make a vs plug-in to scan the solution for where the mapper is being invoked, auto discover what types are being mapped, and update it’s partial class automatically, that would be incredible.
A composite of auto discovering mapperly, with mapster as a fallback if mapperly doesn’t have a mapping, would be the ultimate.
Do I have a map for this? Ok, mapperly. No? Ok, mapster.

Ответить
@DummyFace123
@DummyFace123 - 23.04.2023 01:53

It’s got to go to mapster if it can map anonymous types without configuration

Ответить
@cvelebele18
@cvelebele18 - 19.04.2023 11:39

Mapperly is blazingly fast :)

Ответить
@benlewies8828
@benlewies8828 - 19.04.2023 00:05

Friends don't let friends do automapping. Do manual mapping or use a source generator to generate explicit mapping code during design time.

Ответить
@user-gn7gu1nd1k
@user-gn7gu1nd1k - 13.04.2023 23:28

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

Ответить
@anhcoder
@anhcoder - 13.04.2023 11:13

for big system with high trafic => manual mapper inside model class.
for small -> medium system => automapper.

Ответить
@timseguine2
@timseguine2 - 05.04.2023 07:39

I have never experienced a practical benefit long term from automatic mappers, personally. In theory it would be nice if everything was automated, because the Dto and Model objects normally start in sync. But in practice they eventually diverge to the point that you usually need extra metadata at some point to do the mapping(because the requirements of the Dto don't always match the model types), and at that point I don't see the benefit of using config features of the mapping library. My tendency would be to just start with something like Mapperly and if it breaks or won't work for the use case, it is probably time to swap that mapping method to a manually written one.

Ответить
@nofella
@nofella - 04.04.2023 00:55

Automatic mappers provide an excellent way to accidentally overfill your DTO with sensitive information (given you use the same type for requests and responses which you'll probably do). Also, they introduce unnecessary "magic" to your code to make debugging more difficult, and all of this for automatizing the simplest task ever: mapping. why???

Ответить
@timschwallie1589
@timschwallie1589 - 03.04.2023 16:43

I wonder how Mapster Code Generation approach would have faired.

Ответить
@ritchieedworthy9177
@ritchieedworthy9177 - 02.04.2023 11:57

Great video, extensively use automapper in the way you describe, view to viewmodel but definitely considering the move to mapperly because of the source generation.

Ответить
@matthewsheeran
@matthewsheeran - 02.04.2023 08:02

Mappers are only really required with external or legacy databases or libraries. Aside from that it a good argument for consistent variable naming conventions across code or single developer code bases by developers who are OCD about naming. :-) (I am: I name the same objects consistently across a codebase so I can search and address and refactor cross-cutting concerns easily!)

Ответить
@hyperscreamer
@hyperscreamer - 02.04.2023 06:17

The best mapper to use is no mapper. Didn't watch video yet, but you are unlikely to change my mind

Ответить
@ztBlackGad
@ztBlackGad - 01.04.2023 16:09

Automapper is a good object structure validator. Using built in validate in unit tests so i am sure that external dto after nuget update is still good for my domain objects

Ответить
@xBodro
@xBodro - 31.03.2023 19:46

Just don't use mappers. Ever.
Make a specific constructor for your needs.

Ответить
@tonydrake462
@tonydrake462 - 31.03.2023 17:00

I've been using automapper for like 15 years... never occurred to me that there would be something as easy (or easier) - that was quicker - ok - thanks.... mapperly was just added to my project !! (and good to know I use it correctly - ...

Ответить
@njuniorba
@njuniorba - 31.03.2023 02:18

Mappers? No thanks 👌😉

Ответить
@DR9885
@DR9885 - 31.03.2023 00:20

Benchmarkdotnet only does benchmarks sequentially (not in parallel). But I wonder which approach handles better under load. It would be nice to see this done with NBench w/ RunMode = RunMode.Throughput, this would run parallel.

Ответить
@brianm1864
@brianm1864 - 30.03.2023 03:40

I disagree on the part of not mocking the mapper in your unit tests. We create a separate unit test class for testing the mapper profiles. IMO, this allows for cleaner tests and makes it very easy to catch any issues you might have with your mapper, instead of having to determine if the test failed because of an issue with the method or an issue with the mapper. And if you have multiple methods using the same map, you don't get multiple test failures. You just get one failure for the mapper test that is testing that particular map. I do agree with you on not putting complex logic into your mapper. We, unfortunately, have already gone down that path, and every time I see it, I cringe a little bit. Hopefully some day in the future we will get time to refactor that.

Ответить
@Philippe42460
@Philippe42460 - 29.03.2023 23:58

Thank you for this video, I didn't know about all the different mappers library since we only use AutoMapper.
Well I will consider looking into Maperly lib, it looks quite interesting, and tell about it to my collegues.
Have a good day 🙂

Ответить
@maziarmovahedi
@maziarmovahedi - 29.03.2023 13:10

Hey Nick, Thank you for the great content. You did a video earlier about Mapster and it's source generating feature which I remember it had better performance. Why didn't you include that in the Benchmarks also? 😁

Ответить
@netgeek9725
@netgeek9725 - 29.03.2023 13:02

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

Ответить
@jhdalvik
@jhdalvik - 29.03.2023 11:54

Mapperly doesn't seem to support EF projections, so that's a huge deal breaker for me. Using AglieMapper today, and happy with it, but it's a little worrying that neither AgileMapper nor Mapster (that I was planning to try after this video) has not been updated in over a year.

Ответить