Headspring
agile. software. consulting.

AutoMapper

Our moms taught us to share.

Because so much of our efficiency comes from open-source sharing and re-use of successful code modules, we believe in the power of open source. So much so that we frequently share our own code with other developers; yes, even our competitors.

Automapper

Give your Views only what they need

Utilizing AutoMapper, multiple object relationships of complicated bridging may be easily flattened into more simplistic objects more agreeable for passing to ASP.NET MVC Views. For example, if one wishes to display a table showing names, company names, and street addresses of persons in a contact management application where an Organization may have both numerous Employee children and numerous PhysicalAddress children, it would be more advantageous to make a dummy object to pass to the View than to pass arrays of Organization, Employee, and PhysicalAddress objects to a View and then undertake cross-object matching by way of embedded code which cannot be tested. AutoMapper helps keep the front end clean.

If one were to make a display-friendly version of an Employee object called Dto which only held string type parameters and no references to other objects, then an array of Dto objects might make for good data fuel for the View in the example above. Obviously, one could write code within a Controller to manage the consolidation of Organization, Employee, and PhysicalAddress objects into Dto objects without AutoMapper, but AutoMapper makes it painless. Observe:

List<Dto> contacts = new List<Dto>();
foreach (Employee employee in Employees)
{
    Dto contact = new Mapper.Map<Employee, Dto>(employee);
    contacts.Add(contact);
}

Download AutoMapper

 

© 2001-2010 Headspring. All rights reserved.
Proudly headquartered in Austin, Texas