Onion Architecture vs Clean Architecture Comparison

preview_player
Показать описание

Onion architecture and Clean architecture are often confused. And there's a good reason for that. It's because they are practically identical. Clean architecture is just a repackaging of Onion architecture and Hexagonal architecture principles. I'll compare them in this video, and you be the judge of how different they actually are.

Onion architecture series, Jeffrey Palermo:

Clean architecture, Uncle Bob:

Join my weekly .NET newsletter:

Read my Blog here:

Chapters
0:00 What is the Onion architecture?
3:22 What is the Clean architecture?
5:19 Onion architecture example project
10:17 Clean architecture example project
13:11 Are these architectures different?
Рекомендации по теме
Комментарии
Автор

My architecture is like an Onion - it has many layers, and each time you peel one to expose a deeper layer it makes you want to cry.

iojourny
Автор

Ah, we really needed a video on this topic, a comparison between these seemingly similar architectures. Thanks!

maacpiash
Автор

I see a lot of comments about the Query handlers been in the infrastructure layer. Your reason being: "For a query usually don't care how it's implemented, I only care about the result I get back." This makes sense to me. Will definitely switch to doing this because keeping all the query concerns in the infrastructure is to me a much better separation of concerns. Thank you for sharing

d_
Автор

Great video, also thanks for not focusing on theory only and including the example projects from the scratch. Some things are best learned with an example

yeevirgen
Автор

Nice video! I used to see it as if onion architecture were part of clean architecture! At the end, they shared some of their philosophy. Thanks, Milan!

edwinroman
Автор

Thank you Mr. Jovanovic. You are first one (not FirstOrDefaul :D ) who explained it so cleaner. And with demo. Good job!

dtntracer
Автор

I used to implement my feature handlers in the Application layer even though they use ORM (DbContext). But now I see you bring them into Infrasructure (Persistence) layer. Is this by the rule or it is just your approach?

mshahabfar
Автор

Thanks Milan! Great video! It would be interesting to see Hexagonal architecture comparison as well :)

sushilb
Автор

Good video. 👍A couple of thoughts:
* Service interfaces is useful for unit tests when services depends on other services.
* Recommend also setting the respository impl classes (and others) as internal so they can't be accessed by other layers. Only keep a public class with extension methods to IServiceCollection to add them into the DI flow.

Benke
Автор

I dont know why that i'm not find you before. You have videos for all of my doubts. Thankssss!!

fbrunof
Автор

IMO both these architectures become a mess within a couple of days into development. We ditched them and switched to vertical slice architecture. It has been over an year now and we now maintain huge projects with ease. It would be great if you could compare it as well. Kudos to your work.

NikhilThakralYeah
Автор

Great video, my friend. Now I have a clear concept of those two architectures. Thanks a lot!

saddamhossaindotnet
Автор

These are not necessarily like for like comparisons... For eg, Onion Architecture doesn't appear to use MediatR while Clean Architecture does... In which case Clean Architecture has Application project with a library dependency on MediatR which does not make it technology agnostic... This imo should be in Infrastructure... Pls suggest

expertreviews
Автор

Let me congratulate you because of the videos you do. You are very clear with your explanations!

ignacioinnovo
Автор

11:44 I don't agree with putting the handler down in infrastructure. In that case I would rather do something like an that holds the queries.
But regardless I find both of these architectures very bloated and see little use case of actually using them unless you are building a big monolith, which in todays world with all cloud providers you rarely do.

PelFox
Автор

I have a small question. Why didn't u put the QueryHandler in the Application layer and then inject a repository (which is located in the Domain layer) into that QueryHandler? That way, you can get rid of references to DbContext (external concern).

TrungTran-leht
Автор

Application layer acts somewhat as the request orchestrator ( calling different services using interfaces and also calling domain services/ invariants in the process). Persistence purely deals with database stuff .so shouldn't handlers related to query also be in application layer and use the repository interface ( for getting an article in this example)? This way also provides higher cohesion IMO

DotNetFun
Автор

Milan one question, in your Clean Architecture example, in the Core/Application "layer", isn't it a conceptual flaw to create a dependency on MediatR?

lindermannla
Автор

The front-end command needs to create an order and create a payment at the same time, and this operation should be logically processed at the order application layer? Or is it processing logic at the endpoint?

xmshvwo
Автор

Hey Milan, I've just discovered your videos and really enjoying them. I was just wondering if your Visual Studio theme is something available/easy for us to use? The syntax colors appear easier on the eyes than the default theme. Thanks!

jgclsxp