we are starting a new mulit-tier-architecture. In the past I used AutoMapper to map data transfer objects to business objects and vice versa. A colleague suggested that instead of mapping, we should wrapp the dto inside the business object. Probably by injecting the dto in the business object's constructor. Then we can access the dto's propery values on the fly without mapping.
Question:
Is this approach recommended?
I am aware that if the business object knows the dto you introduce tight coupling. Furthermore you loose some flexibility by creating a 1:1 relationship between business object and dto which normally - with flexible mapping - would be a n:m relationship.
(see: Best Practices For Mapping DTO to Domain Object?)
Is this drawback the reason nobody seems to use the wrapper approach or do I miss someting?
Here is a quick demo what I mean with "wrapping":
public class BusinessObject
{
private Dto dto;
public BusinessObject()
{
this.dto = new Dto();
}
public BusinessObject(Dto dto)
{
this.dto = dto;
}
public int Id
{
get { return dto.Id; }
set { dto.Id = value; }
}
}
public class Dto
{
public int Id { get; set; }
}
hanks for your help!
Torsten