Open NerdAnonymous opened 6 years ago
@NerdAnonymous It's fine for the data layer to depend on the domain layer, it is not fine for the domain layer to depend on any other layer. If you did not put the interfaces in the domain layer, in order to use the data layer repositories, you'd need to have the domain layer depend on the data layer. But because this project uses dependency injection the domain layer does not need to know anything about the data layer as long as those classes implement the domain layer interfaces. I hope that makes sense.
@alexwhb I seem to have a little understanding of what you say. But there are some questions. In the case, data layer is Entities, domain layer is Use Cases, according to Clean Architecture Dependency. It should be that domain layer depends on data layer, but sample is just the opposite, and I don't understand why. Is it just because of the dependence on injection?
@NerdAnonymous no, you're confused. Domain must not depend on any other layer. It is the most inner layer and therefore the most abstract. If you need to fetch some data, you abstract that service with an interface (i.e. a connector) and implemented somewhere else like the data layer.
There are two kinds of dependencies:
The arquitecture prevent the domain layer to depend on any other layer in compile time but in runtime the domain layer would depend on the implementation of the interface (i.e. the data layer) which is fine. This is the so called IoC (inversion of control).
@kevin-barrientos Well, This seems to be the emphasis on the Dependence Inversion Principle principle.But I still not fully understand,so I must work hard at it
why UserRepository interface is in the domain layer?Does this cause the data layer to rely on the domain layer?right?