\$\begingroup\$
\$\endgroup\$
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;
}
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Mar 11, 2014 at 5:16
1 Answer 1
\$\begingroup\$
\$\endgroup\$
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
answered Mar 11, 2014 at 5:54
lang-cs