Sitemap

What is the biggest mistake people do when working on the hexagonal architecture ?

2 min readMar 2, 2025

Not applying properly the dependency inversion

Press enter or click to view image in full size
Direction of dependencies vs flow of calls

That is the 5th principle (D) from SOLID principles. The idea is to invert the dependency in the outside-in direction, else it would be in the same direction (left to right) as for the interaction (or uses), which is the flow of calls.

🤷‍♂️ Consequence

The domain is not well isolated. Then we loose the benefit of using this architecture style. That is to emphasize on the domain isolation, which allow more clarity on the domain model.

❓ How to invert the dependencies

1️⃣ Define the port using interface making abstraction (in java, typescript, …)

2️⃣ Implement adapter by implementing the interface

3️⃣ Inject the adapter to the domain service (or usecase function)

4️⃣ Expose that usecase on the left hand side (driver endpoint)

💪 Example

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
handlerVideoSearch (1 handle function on UI) accessing the context (2 provider as configurator) that delegates the call to the search use case function (4) in the provider which injects the adapter (3) implementing the port
Press enter or click to view image in full size
Video Search use case function (4) — no coupling with any framework

Reference

--

--

Kong To
Kong To

Written by Kong To

Architect, Engineer, Developer, Code, Code Crafter... whatever but code quality matters

Responses (1)