I've been wondering about how to deisn a centralized service for all object search/getter methods for all JpaRepository classes.
so lets say that now i have:
public interface StudentRepository extends JpaRepository<Student, Long>{}
public interface SchoolRepository extends JpaRepository<School, Long>{}
..and bunch of other object repositories.
Now I have a separate service classes that I inject corresponding Repository bean. This introduces issues with circular dependencies: for instance when I need to query school in inside StudentService
and I also need to query student in SchoolService
(both can't have other service in it) So, I want to have it centralized in a single SearchService
which only have 1 method, search(Object, Predicate) and have all Repositories
injected to this 1 class. Then all services would use inject only this SearchService
.
Can anyone help suggest one good design? Right now I can only imagine creating multiple search methods like searchStudent(Predicate)
and searchSchool(Predicate)
in SearchService
and call the proper method when searching objects.. but it kinda doesn't look so elegant..... Thanks for your help!
Aucun commentaire:
Enregistrer un commentaire