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

1 Answer 1

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

answered Mar 11, 2014 at 5:54
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.