-
IntroductionI am using CasesFor example, if I put the ddd classes in the ExampleGiven the
Then I put the
The ArchUnit test is failed with this message:
How can I properly structuring my components? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
In the onion architecture which you are using, the center of the onion contains the domain model. Domain driven design tells you to start your application design at this central ring, focusing on the model and on the business rules it implements, but keeping it free from any technical aspect such as database technology, message broker, REST API, etc. It gives you concepts to model the domain, such as entities, value objects, services or repositories. The DDD annotations and types of jMolecules are means to express these concepts. So ALL OF THEM go into the domain ring of the architecture. It seems that the concept of the repository confuses you. Isn't that where entities are persisted to a database? So shouldn't it be in the infrastructure layer? The repository concept of domain driven design allows you to introduce an element to your domain which gives you access to one or more instances of an entity / of an aggregate root, or allows you to perform queries on them: findById, delete, countHavingExpiryDateInThePast(), etc. At the domain level, the repository is usually just an interface expressing the operations your domain model requires, and you do not care how it is actually implemented. The implementation is then what goes into the infrastructure layer. Out here, you don't need DDD annotations, since the implementation is not part of the domain model. Your implementing class simply extends the repository interface declared in the domain ring and then does whatever is required to meaningfully implement the required functionality. Here you are free to depend on technical libraries such as a specific database driver or dealing with opening and closing transactions. |
Beta Was this translation helpful? Give feedback.
-
I'm learning about this myself, so take this with a grain of salt, but this is my understanding: The purpose of the Entities, Aggregates, Value Objects and Services patterns is to help modelling your domain. Therefore, domain concepts modelled by these patterns should be in the Domain Layer and be annotated with one of the Domain Layer annotations, e.g. @DomainLayer. The repository (interface, at least) is part of the Domain Model as well. The best source for this I can come up with right now is this quote from the Blue Book by Eric Evans (page 124)
and that on the same page and the one before he also describes that domain objects have a life cycle and that repositories address the middle and and end of the life cycle. If you choose to follow the Layered Architecture, the repository implementation will have to be part of the domain layer as well. It can't be part of the Infrastructure Layer, because in Layered Architecture the Infrastructure Layer is not allowed to depend on the Domain Layer (this is also stated in your ArchUnit test output; also see the diagramm in the Blue Book on page 68). The repository implementation then would use the Instrastructure Layer, see this quote of the Blue Book on page 155 (and example given):
To my understanding, if you want the repository implementation to be in the Infastructure Layer, you would have to go for another architectural style, e.g. Onion Architecture. There it would be alloweded that the repository implementation resides inside the Infrastrucutre Layer and references the Domain Layer from there. |
Beta Was this translation helpful? Give feedback.
I'm learning about this myself, so take this with a grain of salt, but this is my understanding:
The purpose of the Entities, Aggregates, Value Objects and Services patterns is to help modelling your domain. Therefore, domain concepts modelled by these patterns should be in the Domain Layer and be annotated with one of the Domain Layer annotations, e.g. @DomainLayer.
The repository (interface, at least) is part of the Domain Model as well. The best source for this I can come up with right now is this quote from the Blue Book by Eric Evans (page 124)