Milan Jovanoviฤ‡
Milan Jovanoviฤ‡

@mjovanovictech

2 Tweets 56 reads Oct 05, 2023
๐—ข๐—ป๐—ถ๐—ผ๐—ป ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ vs. ๐—–๐—น๐—ฒ๐—ฎ๐—ป ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ - is there a difference?
Both architectures have a similar visual representation using concentric circles.
The Onion architecture has:
- Domain entities
- Repository interfaces
- Service interfaces
- Infrastructure, UI, Tests
The Clean architecture has:
- Entities
- Use cases
- Controllers, Gateways, Presenters
- Web, DB, UI, External interfaces
If you only look at this, you might think there's a significant difference.
However, they're more alike than it seems.
The Onion architecture and the Clean architecture revolve around the same idea - a core Domain containing entities.
You have the application services or use cases one layer above the domain.
The direction of the coupling is towards the center in both architectures.
Inner layers define interfaces.
Out layers implement interfaces.
Sounds familiar?
Another name for this is dependency inversion.
The conclusion I came to is that these architectures are interchangeable.
Any differences you see quickly fade when it's time to implement this architecture in a project.
And especially in the .NET community, I'm yet to see implementations of these architectures that are structurally different.
I use the Clean architecture.
By extension, I also use the Onion architecture.
And I find one of the names "cleaner" (pun intended).
If you liked this, consider joining The .NET Weekly - my newsletter with 29,000+ engineers.
Join us here โ†’ milanjovanovic.tech
Did you consider these architectures to be different?

Loading suggestions...