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?

asked Aug 13, 2021 at 20:52
2
  • Domain layer don't communicate with infrastructure layer. Domain layer is not aware of infrastructure layer existence. Commented Aug 14, 2021 at 1:10
  • Domain layer don't have/know about Save or Load methods Commented 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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.