I am (or, shortly, will have been) using AutoMapper to map a bunch of business objects to a bunch of WCF DTOs. It seemed like a decent trick--there was a fair amount of troubleshooting to do at the .CreateMap
level, but it overall felt worth it. Until I decided to hide my business logic from outside the assembly.
The BOs and the mapper live in the same project; they spin off external-assembly DTOs, which are public
(and would need to be to get through the channel anyway). There is no need to expose the BOs, as the DTOs now do that job, so I thought I'd reset their accessors to internal
. Kaboom goes automapping. To illustrate:
(code from BLL, same as AutoMapping)
public class TestObject
{
private int _myID;
public int MyID
{
get { return _myID; }
set { _myID = value; }
}
}
(code from service layer)
public class TestObjectDTO
{
private int _myID;
public int MyID
{
get { return _myID; }
set { _myID = value; }
}
}
this will work
Mapper.CreateMap<TestObject, TestObjectDTO>();
until I do this:
internal class TestObject
...
or even just this, in TestObject
:
internal int MyID
Can anyone explain this to me? I'll stop short of calling it a "bug", but it certainly seems to contradict the entire purpose of reflection-based mapping, i.e. to allow objects of different purposes to scale together fluently. Why can't AM handle the mapping, and let me control the accessors?