I would like to clarify the role of the service layer in my mind. I have a classic architecture for my app : Controller => Service => DAO (JpaRepository).
The service perform my business logic and are annotated with @Transactional.
Let's take a simple example and say that I have two entities:
- Company
- Project
A company can have several project and a project can be in one company. Let's assume that there is one controller for each entity. For example, if I want to get all the projects of one company, I have two options.
- Calling ProjectService in my CompanyController and create a method in the ProjectService that get all projects by a company ID (by a query in the DAO). Then, I will have several @Autowired (for all services) in my controller but only one in my service.
- Adding a FindAllProject in my CompanyService that will call the project DAO method. Then, I will have only one @Autowired in my controller but several in my service.
What would be the best approach ?
Thanks in advance for your answer.
Seb
ProjectService
,CompanyService
, andCompanyController
have too much responsibility? Maybe there should be finer grained implementations such asProjectSearchService
,CompanySearchController
, andCompanySearchService
. – Andrew S