1

In a Layered Architecture with Dependency Inversion Principle we have some Application Services (in Application Layer) and some Domain Services (in Domain Layer).

Now I want to do some validations on Object Compositions. In the red book, on chapter 5 under Validating Object Compositions somewhere it says:

But it may be best to manage that kind of validation using a Domain Service. The Domain Service can use Repositories to read the Aggregate instances it needs to validate.

  • Doesn't this means that repository interfaces live in domain layer?
  • If yes, are there any un-told truth about these repository interfaces? (maybe they can only fetch aggregates by id?)

I know that this question has been asked so many times. But I find most of the answers neglecting the blue and the red book this stackexchange thread for example

Saeed Farahi
  • 53
  • 1
  • 5
  • Probably will be a useful answer https://stackoverflow.com/questions/71996305/repository-implementation-in-application-domain-and-infrastructure-layer-ddd/72036702#72036702 – Eugene Jun 07 '22 at 22:11
  • 1
    @Eugene Nice explanation on that topic – Saeed Farahi Jun 08 '22 at 21:35

1 Answers1

1

Doesn't this means that repository interfaces live in domain layer?

Yes, repository interfaces live in the domain layer for sure and usually domain services and application services (a layer above) are their consumers.

If yes, are there any un-told truth about these repository interfaces? (maybe they can only fetch aggregates by id?)

Repositories are intended to fetch and modify aggregate roots, be it for validation or any other purpose. The fetch doesn't necessarily have to happen with id, it may happen with other parameters as situation demands.

Farhan Nasim
  • 773
  • 4
  • 13