Quantcast
Channel: User Álvaro García - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 41

Where to define the interfaces of the infrastructure in a clean architecture and DDD?

$
0
0

I have been reading about clean architecture and following Domain-Driven Design. In all the examples I have found, the interfaces of the repository are defined in the domain.

However, it is in the application layer where the repository interface is injected, and the interface is implemented in the infrastructure layer.

From what I understand, the interface should be defined in the layer that needs the resource. In this case, the repository is needed to retrieve data from the database. This layer is the application layer. The domain shouldn’t know where the data is coming from; it should just receive the data it needs to perform its tasks.

Therefore, the domain should be agnostic about persistence. In theory, the domain doesn’t know if the data will be saved or not. The application could run in memory and not save anything. The domain shouldn’t concern itself with persistence.

Given this, I was wondering why the repository interfaces are not defined in the application layer.

Furthermore, why should the domain define any interface if it is supposed to be isolated, being the core of the application? Shouldn’t the application layer provide the domain with all the data it needs to perform its tasks?

In summary, I would like to understand the logic behind defining the interfaces in the domain layer. I am also curious if it is a good or bad idea to define the interfaces in the application layer.

Thank you very much.


Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>