InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

AutoMapper 1.0 For .NET Released

Posted by Jon Arild Tørresdal on Feb 05, 2010

Sections
Architecture & Design,
Development,
Operations & Infrastructure
Topics
.NET ,
Open Source

The open source project AutoMapper written by Jimmy Bogard has been actively developed for about a year and recently got to the 1.0 mark. AutoMapper is a convention based object-to-object mapper often used to (but not restricted to) flatten complex object models to DTOs, commonly used in ViewModels and crossing service boundaries.

AutoMapper provide the user with a fluent configuration API as well as using conventions to do the auto part of the mapping. Some of AutoMapper’s features include:

  • Flattening
  • Projection
  • Configuration Validation
  • Lists and Arrays
  • Nested Mappings
  • Custom Type Converters
  • Custom Value Converters
  • Custom Value Formatters
  • Null Substitution

AutoMapper is a one-way mapper. Meaning no built in support for mapped objects to write back to its original source, unless the user specifically create a reverse mapping after the mapped object is updated. This is by design, since having a DTO write back to e.g. a domain model would (among other things) take away its immutability, and is often considered an anti-pattern. In such a scenario the Command Messages is often used as a better solution over bidirectional mapping. However, there are a few circumstances where one could defend bidirectional mapping, like for very simple CRUD applications. One framework that does support bidirectional mapping is Glue.

On the roadmap for AutoMapper, support for Silverlight and Mono is on top of the list. Also “First-class reverse mapping support” was listed, so InfoQ asked Jimmy if he’s planning to add bidirectional mapping support:

Personally, I don't really want to support two-way mapping, as those asking for it are really asking for first-class ActiveRecord support in ASP.NET MVC (something that Rails still has the MS solution beat by a large margin).  If you look at how Rails processes form posts, it's a straightforward affair.  I'm still hoping not to do the feature, as I think it works against design concepts like POJO/POCO, the domain model pattern, etc.  More people are asking for a Silverlight release in any case :)

Do you think AutoMapper should add bidirectional mapping?

Comparison with Dozer for Java? by Martin Klinke Posted
  1. Back to top

    Comparison with Dozer for Java?

    by Martin Klinke

    I have used Dozer (dozer.sourceforge.net/) for "domain object" to "DTO" mapping in Java and was very satisfied with this approach. So far I haven't found a similar solution for .NET/C#. Has anyone experience with both "worlds" and can recommend a tool that does with C#-objects what Dozer does with Java-objects? Is it AutoMapper?

    Though Dozer has two-way mapping capabilities and I have incoming and outgoing objects and thus mapping requirements, I didn't use Dozer's built in approach. Rather I have defined a separate mapping for each direction, because I may want to transfer some properties on the way out but not automatically write back the values that are submitted by a service consumer (e.g. timestamps for optimistic locking - I do need to use them, but I don't want them to be mapped back as this would work against the concept of locking ;).

    So I don't really need bidirectional mapping. I think AutoMapper would be a solution for the above mentionned requirements and would be glad to hear some real-world experience.

Educational Content

Jesper Boeg on Priming Kanban

In this interview, Jesper Boeg, author of the new InfoQ book – Priming Kanban, discusses the keys to using Kanban effectively, and how to get started if you are currently using other approaches.

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.