Should service layer return only model objects? There are some posts about it on the web (here and here are some SO posts) but none with a good example.
All I see is something like this:
Services should care only about the problem domain, not the view that renders results. Return values should be expressed in terms of domain objects, not views.
I'm feeling that I am missing something here.
Looking at the example below ... Suppose I want to return a list of all movies, but, I need a boolean
flag - something like hasLike
- to show if I already liked it before. How is it possible returning only models from service layer?
In short ... how do I return meta information
from service layer following this approach? Is that possible?
Model
public class Person
{
public int PersonID { get; set; }
public string Name { get; set; }
public ICollection<Movie> FavoriteMovies { get; set; }
public ICollection<MovieLikes> Likes { get; set; }
}
public class Movie
{
public int MovieID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
public class MovieLike
{
public int MovieLikeID { get; set; }
public int PersonID { get; set; }
public int MovieID { get; set; }
public DateTimeOffset Date { get; set; }
}
Service
public class MovieService : IMovieService
{
public Movie Get(int id)
{
}
public Movie GetByName(string name)
{
}
public IEnumerable<Movie> GetAll()
{
return unit.DbSet<Movie>();
}
}