Friday, October 2, 2009

How To Save Time Writing your Presentationmodel

Inspired by this article  about how to use DTO and seperate your domainmodel from the client in a presentationmodel, I started rewriting some of my code.

But what have always bin a real pain in the a.. , is writing DTO´s for seperation concern between layers.

Again a good colleauge of mine told me about AutoMapper. A component for doing “object to object” mapping easily. Yesterday I couldn’t see the light, today I’m just blessed by the power of AutoMapper.

I was just about to write my own mapper, when I found AutoMapper. By default you just provide a source and target object e.g. Domain object and DTO and AutoMapper will map by properties. Say you have a Customer.Name will automatically map to CustomerDTO.Name. Now thats what I call a real timesaver.

And did I mention it has a lot of other features for configuration all of which can be done by Fluent, just to please Resharper.

1 comment:

Rolf Therkildsen said...

I like Dino Esposito article and agree that AutoMappers could solve some of the drawbacks that Esposito mentions.

By the way, I never thought about the difference between domain logic and application logic before. Nice point.

Thanks for referring Dino Esposito’s article.