2
\$\begingroup\$

I'm wondering if it's bad practice to couple my DTO to my domain object like this and pass the object itself into Create(). Is it better to just give the parameters needed to perform the creation?

public static Playlist Create(PlaylistDto playlistDto, IUserManager userManager, IPlaylistManager playlistManager)
{
    Playlist playlist = new Playlist
        {
            Id = playlistDto.Id,
            Items = PlaylistItem.Create(playlistDto.Items, playlistManager),
            Sequence = playlistDto.Sequence,
            Title = playlistDto.Title,
            User = userManager.Get(playlistDto.UserId)
        };

    return playlist;
}
\$\endgroup\$
1
\$\begingroup\$

If the Playlist is an external dependency then it might make sense to use an extension method like:

public static Playlist Create(this PlaylistDto playlistDto, IUserManager userManager, IPlaylistManager playlistManager)
{
    Playlist playlist = new Playlist
        {
            Id = playlistDto.Id,
            Items = PlaylistItem.Create(playlistDto.Items, playlistManager),
            Sequence = playlistDto.Sequence,
            Title = playlistDto.Title,
            User = userManager.Get(playlistDto.UserId)
        };

    return playlist;
}

other than that, if the code is under your control, why not just make another constructor and do away with the static method

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.