Following the classic 3 layer architecture
-
domain Model (a list of entities live there and has no dependencies)
-
DAL layer – My Repositories lives there with DBContext implementation (Ado.net) Dal return pure entities ( reference domain model)
-
Service Layer ( Business Layer ) expose methods of repositories ( reference DAL Layer and Domain Model)
-
UI Layer(WPF) > Service Layer(BLL) > Repositories
MY question is related to the following concepts
Reading article upon article, state that Data Repositories should return only entities.
e.g
public interface ICustomerRepository
{
IEnumerable<Customer> FindByText(string TextToFind);
Customer GetByID(string ID);
IEnumerable<Customer> GetAll();
void Update(Customer CustomerToAdd);
void Delete(params string() Ids);
}
Then I ask my self.
- What if i need to show a list of customer with some other complex inner join, union query.
- end a lot of more other queries related to other view requirements.
(actually in our accounting application 90% of the screens are never shown data in their pure form(entities). always they are in form with other inner joins , sum amounts etc..
e.g customer : Name,AccountName(inner join from accounts), Balance (inner join from ledger), etc..
Some state that is ok to put this query in repository others say is not good because is not an entity
Where this logic goes? since repositories dose not allow me to return other than entity model.
and also CustomerService in BLL Layer ( dose not allow me to return DTO in methods)
I read that CQRS comes to the stage to solve UI Queries
Ok, lets say that i follow cqrs for query side ( lets skip command as commands and updates go through repository)
Now I end up having:
- CustomerRepository (DAL Layer)
- CustomerService (BLL – service layer) which is just exposed repository methods and maybe some other related things
- CustomerQueries class (BLL – service layer) which contain any complex
query (DTO) related to customer and has direct connection to sql converting datatable to relative dto and give it to UI layer
My question is this proper way to follow?
which layer CQRS live? in (business layer which some call it service layer?) or in DAL Layer where my repositories live
Many times i found my self much easy way just to type CustomerServices. and the intellisense giving me all the related information I might want from customer, some functions return dto others return some amounts other times just some bool to check some rules which require complex sql queries)
The problem is that, since CustomerService as they say, should only be responsible to call relative CustomerRepository fetch or update only things related to repository,
where i put logic for complex queries and in which layer?