We are at the design stage of developing an application.
We decided to implement DDD oriented design.
Our application has a service layer.
Each method in the service has its own task.
Sample
let's consider a user service.
This method gets all users
public User GetAll()
{
//codes
}
Now if I want to sort all users by name.
Option-1
Use another method
public User GetAllAndOrderByAsc()
Or
public User GetAllAndOrderByDesc()
Different method for each different situation.
it doesn't look good at all
Option-2
Continue query at Api or Application level
public IQueryable<User> GetAll()
{
//codes
}
Api or Application Level
var users = from u in _userService.GetAll()
select u;
switch (sortOrder)
{
case "name_desc":
users = users.OrderByDescending(u => u.Name);
break;
case "name_asc":
users = students.OrderBy(u => u.Name);
break;
default:
users = students.OrderBy(u => u.Name);
break;
}
The options that come to my mind are limited to these.
am I making a mistake somewhere or couldn't grasp the logic. would you help me?
Aucun commentaire:
Enregistrer un commentaire