I am applying the principles of Hexagonal Architecture (Ports and Adapters) and one aspect is slightly bothering me. In my opinion, the ports and adapters of the secondary actors should completely be isolated from each other. No dependencies between them. Maybe this is a false expectation but it instinctively feels right to me.
I am having a hard time enforcing this separation. A very simple example is the following use case (don't worry about the details):
There is
Logging
secondary port that is responsible for creating/handling the logs of the application. The adapters are not that important but let's just assume that there isStandardOutputLogging
adapter for now; it just sends the logs to standard output.There is also another port named
EmailSending
which is responsible for sending e-mails. Again, the adapters don't matter too much.The issue happens when I want to log what happens in the e-mail sending functionality. The
EmailSending
adapters need a handle on theLogging
port. This does create a dependency between the two secondary ports of the application.It is also an issue during the wiring of the system as well.
Logging
adapter should be created first and then passed to theEmailSending
adapter. That also creates an implicit dependency.
How do we solve this?