Best practices AutoMapper. Should I ask the DAO for information about the conversion from DTO to a domain object?

/// <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 tells me that it is wrong for AutoMapper to use DAO to perform mappings from DTO to domain.

I don’t understand why this is bad practice, and I don’t understand how it would be possible to work effectively with my null-referenced domain object.

Can anyone explain? Thanks

+4
source share
1 answer

, . . , AutoMapper (DE) . DE . , , , . , . , -.

, . DTO, , DE, DTO DE ? , .

, , , DE ORM, Onion Architecture DE . AutoMapper .

+2

Source: https://habr.com/ru/post/1529724/


All Articles