I've been scratching my head about this for a few months and I've still been able to satisfactorily convince myself that I have the right answer. We have a, very typical, situation where we have dependencies between multiple layers of our application where each layer is in its own assembly. As an example, our application layer uses the repository layer to retrieve data so pretty standard. My question is, where would the abstraction (interface in this case) live and why? In the example given, should it go in the Application layer or the Repository layer or a separate abstractions assembly?
Based on the diagram and description in The Clean Architecture description (not something we're particularly adhering to) I've placed them in the Application layer so that all of the dependencies are pointing inwards but I'm not sure if this is right. I've read quite a few other articles and looked at countless examples but there is very little in the way of reasoning as to where the abstractions should live.
I've seen this question but I don't believe it answers my question unless of course the actual answer is it doesn't matter.
It is called Dependency Inversion Principle, because the classic dependency direction from a higher level module to a lower level is inverted as follows:
| HigherLevelClass -> RequiredInterface | <= LowerLevelClassImplementingTheInterface |
So the inverted dependency is pointing from the lower level module to the required abstraction for your higher level module. As the client module (your application layer) requires a certain lower level functionality, the related abstraction (your repository interface) is placed near the client module.
All descriptions I know use the package construct for explaining this. However, I see no reason why this should not be true for modules or layers.
For details, e.g. see: http://en.wikipedia.org/wiki/Dependency_inversion_principle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With