Search code examples
javadaobusiness-logic

Inject a class which provides the services to ProjectDao


I have got a class which behaves as a center of API services. I need to use one of the services in this class to filter out the result from database query.

Is it a good practice for me to inject this service class into a ProjectDaoImpl class?

I am asking this because I have found some examples which only use the service at business logic level (eg ProjectLogicImpl) but not in DAO level.


Solution

  • No, it's not a good practice. The service layer should depend on the DAO layer, but the reverse should not be true. But you may have a DAOHelperService object in the DAO layer that is injected in DAOs and in services. That wouldn't break proper layering.