Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why do you do this? #272

Open
NerdAnonymous opened this issue Mar 1, 2018 · 4 comments
Open

Why do you do this? #272

NerdAnonymous opened this issue Mar 1, 2018 · 4 comments

Comments

@NerdAnonymous
Copy link

why UserRepository interface is in the domain layer?Does this cause the data layer to rely on the domain layer?right?

@alexwhb
Copy link

alexwhb commented Mar 1, 2018

@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.

@NerdAnonymous
Copy link
Author

@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?

@kevin-barrientos
Copy link

@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:

  1. Compile time dependencies
  2. Runtime 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).

@NerdAnonymous
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants