In onion arch. we have multi layer structre:
UI (User interface). BL (Business Logic / Services). RE (Repositories).
UI uses BL to get data from RE with some conditions, my question is which is better approach (as standard) to get data from BL:
In Repository (Data Access Layer):
public class PersonRepository
{
PersonEFDbContext context = new PersonEFDbContext();
public IEnumerable<Person> GetPerson(Expression<Func<Person,bool>> Where)
{
return context.PersonsList.Where(Where).ToList();
}
}
Entity:
public class Person
{
[Key]
public int Id { get; set; }
public int NationalityId { get; set; }
}
case 1:
public class PersonProvider
{
private PersonRepository repository { get; set; }
public IEnumerable<Person> GetPersonListByNationality(int NationalityId)
{
return repository.GetPerson(p => p.NationalityId == NationalityId);
}
}
then I have to use it in UI like this way:
public class PersonListViewModel
{
IEnumerable<Person> PersonsList { get; set; }
public PersonListViewModel(PersonProvider Provider, int NationalityId)
{
PersonsList = Provider.GetPersonListByNationality(NationalityId);
}
}
case 2:
public class PersonProvider
{
private PersonRepository repository { get; set; }
public IEnumerable<Person> GetPersonList(Expression<Func<Person,bool>> Where)
{
return repository.GetPerson(Where);
}
}
then I have to use it in UI like this way:
public class PersonListViewModel
{
IEnumerable<Person> PersonsList { get; set; }
public PersonListViewModel(PersonProvider Provider, int NationalityId)
{
PersonsList = Provider.GetPersonList(p=>p.NationalityId == NationalityId);
}
}
So where is the right place to set conditions, which one is better for later maintenance ?