BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News AutoMapper 1.0 For .NET Released

AutoMapper 1.0 For .NET Released

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?

Rate this Article

Adoption
Style

BT