1

I'm trying to get a grasp of the Clean Architecture. In the examples I found the typical solution structure consists of three projects: Core, Infrastructure, and Presentation/UI. The Core project must not have any dependencies. It contains the domain objects and business rules. The Infrastructure contains all external concerns: persistency, file system, web etc.
What I don't understand is that since the Core doesn't have any dependencies and it contains all the business rules, how does it communicate to the Infrastructure layer? For example, if it needs to send an email or save/load a file from the system how does it request such action from the Infrastructure layer?

2
  • Domain layer don't communicate with infrastructure layer. Domain layer is not aware of infrastructure layer existence.
    – Fabio
    Aug 14, 2021 at 1:10
  • Domain layer don't have/know about Save or Load methods
    – Fabio
    Aug 14, 2021 at 1:19

1 Answer 1

5

This happens when you follow the Dependency inversion principle.

Your core layer will define an interface, such as Sender. Your infrastructure layer will depend on the core layer and provide an implementation of the interface, such as a EmailSender. Any class in your core layer which requires to send an email will only depend on the interface and remain ignorant of how it is actually implemented. Therefore, the core layer does not have any knowledge of the technical details of sending an email as they reside only in the infrastructure layer.

Of course, at some point, you will need to pass a concrete implementation of the interface when constructing your objects. This generally happens in some main module, which depends on all your different layers and act as a glue between all of them. It only contains the code require to run your application, leaving the business logic encapsulated and isolated in the core layer.

1
  • I completely forgot about dependency injection and inversion of control techniques, totally slipped my mind. Thank you.
    – blablaalb
    Aug 13, 2021 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.