Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My two biggest arguments for Automapper:</p> <ol> <li>Why write something custom when you can rely on a well-tested, convention-based library to do for you? </li> </ol> <blockquote> <p>Yes, you can write extension methods to move data between properties. But, why would I write countless mapping lines just for shipping data across types, e.g. </p> <p><code>Property1 = original.Property1; Property2 = original.Property2;</code></p> <p><em>especially</em> when you are doing thing like this:</p> <p><code>Property1 = (MyEnum)Enum.Parse(typeof(MyEnum), original.Property1);</code></p> <p>It's messy plumbing code that is time-consuming to write, and you have better things to do with your time, like building useful features, to mess around with things like this. AutoMapper provides all the convention you need to get the first case done for free, and simple patterns for managing the more complex scenarios where you are reducing shapes or changing types.</p> </blockquote> <ol> <li>The maps themselves are easily testable.</li> </ol> <blockquote> <p>Again, you can write your own methods. However, if you're doing things correctly, you have corresponding tests to cover all the cases inherent with the custom code you just wrote. <em>Or</em>, you could just loads your maps up and ask AutoMapper if your mapping configurations are correct.</p> </blockquote> <p>My caveat argument against Automapper:</p> <ul> <li>If you start having to write enough exceptions to the map that you have pretty much stopped relying on configuration, it's likely become a leaky abstraction. (In actuality, the problem probably lies in the design of your domain and AutoMapper is just the first constraint that signals the upstream problem). </li> </ul> <p>I'm not saying it's the panacea for mapping code (it has its quirks) but the time expended spiking with it to see if it fits your solution is worth the investment.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload