0
votes

We are developing a application using eclipse, spring, ddd and the repository pattern Our current secenario is composed by the following plugins

  1. Plug-in Domain.project: contains the interface Repository.class.
  2. Plug-in Repository.project: contains the different implementations of the interface Repository.class, for instance ExampleRepositoryImpl.class. So this plug-in has Domain.project plug-in on its dependencies.

We have created Service.class, in Plug-in Domain.project, which is calling through injection, one of the implementations of Repository implemented on the Plug-in Repository.project. But the injection is not solved properly.

  1. We are no able to add a dependecy to Repository.project from Domain.project, cause this would throw a redundancy cyclic error.
  2. Also, since we are following the DDD approach the Domain.project could see the rest but opposite.

Thank you so much, Kind regards,

Eclipse, Spring, DDD and the repository pattern

2
First, why separate package for repositories? Repository interfaces live together with domain classes in the same package. Second, repository implementation project needs to depend on (ie. "see") the domain project, not the other way around. Why would the domain project want to see implemenation details of the RepositoryImpl classes? - Markus Pscheidt
Thank you very much Markus. Please note the new entry below - Brais Omar Moreno Cidrás

2 Answers

0
votes

As you said, the repository interfaces are on the domain project. We have create one project per every implementation of the interfaces included on the domain project. For example, we have created a project for the implementation for the JBDCRepository, another one for the PureQueryRepository, another one for the JsonRepository, and so on. For this reason the repository project implementations have a dependency ("see") the domain project, but the domain project doesn't have any dependency to the repository project implementations. So, our problem takes place when we would like to choose/inject through Spring any of these repositories, since the domain project doesn't see any of the repository project implementations we get a ClassNoFoundException

Kind regards, Brais Cidrás.

0
votes

The domain shouldn't care which implementation it uses - that's why you separate repository interface from repository implementation in the first place.

In order for you to decide which implementation to use, think of how dynamic the selection of the implementation is:

  • Decide at server startup -> use e.g. Spring Profiles: Use a profile called "jdbc", another called "json", and so on, and activate the desired profile when starting the application. In this way, only the repository implementations of the specified profile will be instantiated and injected.

  • Decide at class level -> use e.g. Spring Qualifiers If one Spring bean needs the "jdbc" implementation of your repository, whereas another one needs the "json" implementation of the same repository, then instantiate each implementation with the respective qualifier name and inject the desired repository implementation by specifying its qualifier.