/// <summary>
/// Initialize the AutoMapper mappings for the solution.
/// http://automapper.codeplex.com/
/// </summary>
public static void CreateAutoMapperMaps()
{
IDaoFactory daoFactory = DependencyResolver.Current.GetService<IDaoFactory>();
Mapper.CreateMap<Error, ErrorDto>()
.ReverseMap();
IPlaylistDao playlistDao = daoFactory.GetPlaylistDao();
IUserDao userDao = daoFactory.GetUserDao();
Mapper.CreateMap<Playlist, PlaylistDto>();
Mapper.CreateMap<PlaylistDto, Playlist>()
.ForMember(playlist => playlist.User, opt => opt.MapFrom(playlistDto => userDao.Get(playlistDto.UserId)));
Mapper.CreateMap<PlaylistItem, PlaylistItemDto>();
Mapper.CreateMap<PlaylistItemDto, PlaylistItem>()
.ForMember(playlistItem => playlistItem.Playlist,
opt => opt.MapFrom(playlistItemDto => playlistDao.Get(playlistItemDto.PlaylistId)));
Mapper.CreateMap<ShareCode, ShareCodeDto>().ReverseMap();
Mapper.CreateMap<User, UserDto>().ReverseMap();
Mapper.CreateMap<Video, VideoDto>().ReverseMap();
Mapper.AssertConfigurationIsValid();
}
A friend is telling me that it is bad practice for AutoMapper to rely on DAOs to fulfill mappings from DTO to Domain.
I don't understand why this is bad practice nor do I understand how it would be possible to effectively work on my domain object with null references.
Can anyone explain? Thanks