Onion Architecture vs Clean Architecture Comparison

  Рет қаралды 46,315

Milan Jovanović

Milan Jovanović

Күн бұрын

Пікірлер: 186
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Get the source code for this video for FREE → the-dotnet-weekly.ck.page/clean-onion Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@GreatTaiwan
@GreatTaiwan 6 ай бұрын
why not just in github ?
@iojourny
@iojourny Жыл бұрын
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.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
😂
@Forshen
@Forshen Жыл бұрын
😂
@lugebeatzz8747
@lugebeatzz8747 2 ай бұрын
😂
@maacpiash
@maacpiash Жыл бұрын
Ah, we really needed a video on this topic, a comparison between these seemingly similar architectures. Thanks!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Glad you liked this one :)
@d_6963
@d_6963 2 ай бұрын
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
@MilanJovanovicTech
@MilanJovanovicTech 2 ай бұрын
Another thing I do is leave them in Application layer, and simply use EF/SQL/Whateveriwant. Not pure CA, but same result with less indirection.
@d_6963
@d_6963 2 ай бұрын
This is how I am currently doing it. It works, but having infra stuff like the ORM in the app layer really bothers me. That is why it made sense when you mentioned having the Query Handler in the infra layer. However, after thinking about this for a bit, I realised this is a separation concern for me. I will add an extra layer, the Query Layer, dependent on the infra and domain layers; this is where the query handler will be. The presentation layer will then depend on the query layer and app layer. Queries go to the Query layer, and Commands go to the Application layer. This approach aligns with the CQRS pattern and would align with my architectural concerns. I have even considered renaming the app layer to the command layer. I have been trying to shoehorn the CQRS pattern into clean architecture, so the results have bothered me. But this would clear that up for me. I'm rambling here a bit; it's easier for me to formulate an idea when I have to define it, and it's also good to have feedback on it when you put it out there.
@yeevirgen
@yeevirgen Жыл бұрын
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
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
I think this aligns nicely with my way of teaching. Some theory, but more focus on practice and practical implementations
@edwinroman30
@edwinroman30 Жыл бұрын
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!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Yeah, they are interchangeable
@d3tn3tracer
@d3tn3tracer Жыл бұрын
Thank you Mr. Jovanovic. You are first one (not FirstOrDefaul :D ) who explained it so cleaner. And with demo. Good job!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Glad it was helpful!
@Benke01
@Benke01 Жыл бұрын
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.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Great suggestions 👌
@riseofaskari
@riseofaskari 9 ай бұрын
One question here, in case of using onion architecture, service interfaces would be placed in application layer or domain layer?@@MilanJovanovicTech
@d_6963
@d_6963 4 ай бұрын
​@@riseofaskariAll the interfaces that are used in the infrastructure layer are stored in the domain layer.
@saddamhossaindotnet
@saddamhossaindotnet Жыл бұрын
Great video, my friend. Now I have a clear concept of those two architectures. Thanks a lot!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Don't you think they are the same?
@fbrunof
@fbrunof Жыл бұрын
I dont know why that i'm not find you before. You have videos for all of my doubts. Thankssss!!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Happy to help 😁 Hope you enjoy the other videos :)
@sushilb7994
@sushilb7994 Жыл бұрын
Thanks Milan! Great video! It would be interesting to see Hexagonal architecture comparison as well :)
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Great suggestion!
@sotsch9280
@sotsch9280 Жыл бұрын
Its the same as the clean architecture. Just another visualization in my opinion.
@ignacioinnovo5308
@ignacioinnovo5308 9 ай бұрын
Let me congratulate you because of the videos you do. You are very clear with your explanations!
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Thank you very much!
@mshahabfar
@mshahabfar Жыл бұрын
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?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Just an idea I got from Jeffrey Palermo's original Onion Architecture repository.
@sotsch9280
@sotsch9280 Жыл бұрын
It have to be in application layer because you often want more than just use a database. If the use Case need more information or requires more than one infrastructure, you are forced to gather this in application.
@NikhilThakralYeah
@NikhilThakralYeah Жыл бұрын
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.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Within a couple of days? I've maintained CA/Onion systems for years, and they didn't become a mess. Maybe it's not the architecture, but the engineers...
@acuencadev
@acuencadev Жыл бұрын
@@MilanJovanovicTech "Maybe it's not the architecture, but the engineers...". Damn...
@TrungTran-le2ht
@TrungTran-le2ht Жыл бұрын
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).
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Repositories should return domain entities. If I use that in a query handler - it's not optimal performance. If I start returning DTOs from the repository, it starts getting too many concerns.
@ynotj5386
@ynotj5386 9 ай бұрын
I was asking myself the same exact question. Imo, the not using the repository in the query handler for performance reasons argument doesn't hold water. As a matter of fact, the approach presented in this video leaks application layer specific logic, i.e. the business logic, in the external layer. The Article Service is practically mapping user input to domain entities & passing them to the Article Repository. The Query Handler should be no different; it should map domain entities returned by the repository to dtos which are then consumed by the external layers.
@PelFox
@PelFox Жыл бұрын
11:44 I don't agree with putting the handler down in infrastructure. In that case I would rather do something like an ArticleQueryService/ArticleReadRepository 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.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
What is a "big monolith"?
@hermesfranklin
@hermesfranklin 7 ай бұрын
I can't see differences, just synonyms, because all the examples I see of both have things implemented in one and not in the other, but that don't belong to the model, this takes the focus away from the comparison, it would be interesting to leave preferences aside and focus on implement the same functionalities in both, without a mediator, without a mapper, and all these things that can be implemented in both, but are not necessary to compare, especially if there is only an example of the code in Onion or Clean
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
Because it's the same thing
@DotNetFun
@DotNetFun Жыл бұрын
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
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
What would be the value of that indirection via the repository?
@DotNetFun
@DotNetFun Жыл бұрын
@@MilanJovanovicTechPreventing references to any external concerns in application layer ( just like the thing you did in creating an article command handler)
@trouserMuncher
@trouserMuncher Жыл бұрын
Свака част, феноменалан видео. Посебна похвала за пример, остали само теорију понављају... 60 секунди твог примера и све сам скапирао. Жив био.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Хвала пуно. Жив био. 😁
@adshtecnologia4335
@adshtecnologia4335 Жыл бұрын
Uncle Bob didn't tell us "how to implement Clean Architecture". so for me "Architecture" is just Onion. The concept of Clean Architecture could simply be called "Clean Code Design"
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
That's an odd take
@adshtecnologia4335
@adshtecnologia4335 Жыл бұрын
@@MilanJovanovicTech It is simple, Clean Architecture does not strictly specify how to organize the outer layers. Onion Architecture, on the other hand, is more prescriptive about organizing the external layers, requiring them to contain specific infrastructure details, such as database access and UI.
@adrianspikes6454
@adrianspikes6454 Жыл бұрын
I prefer 📂 s named UseCaseViaService and UseCases then individual folders for each use. More for future organizational planning.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Expand on this with an example? I'm curious what you mean
@sunzhang-d9v
@sunzhang-d9v 10 ай бұрын
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?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
You can process them both on the backend, as one transaction.
@expertreviews1112
@expertreviews1112 Жыл бұрын
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
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Not necessarily, architecturally they are pretty identical. Disregard the implementation details.
@RunawayYe
@RunawayYe Жыл бұрын
A great comparison and explanation, thank you!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Glad it was helpful!
@JoeWarren-z4i
@JoeWarren-z4i Жыл бұрын
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!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
It's VS dark theme + ReSharper syntax highlighting
@kristianaranda
@kristianaranda Жыл бұрын
Great video Milan!!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Thanks a lot :)
@donaldmafa
@donaldmafa Жыл бұрын
Thanks Milan for this explanation. When building an enterprise application with lots of entities, would it be practical to use the Clean Architecture, it appears to me that you would need a lot of query handlers and commands, which is a lot of code compared to using services? Then secondly, is there a need to use a Repository pattern if using EF Core, is this not just an extra layer?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
You're free to use EF directly. It's more or less the same amount of code (+-10%) but it's in different places.
@kodindoyannick5328
@kodindoyannick5328 8 ай бұрын
I like so much your approach by pratice. Thank you Milan.
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
Happy to hear that!
@lindermannla
@lindermannla Жыл бұрын
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?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Why? It's just an in-memory messaging library
@lindermannla
@lindermannla Жыл бұрын
Yes, I understand it is a messaging library. But, if I wanted to use these use cases in another application, isolating it in a project, wouldn't it be better not to create this dependency, since in the other application I might not use MediatR?
@pilotboba
@pilotboba Жыл бұрын
@@lindermannla If you are really concerned, you could only reference Mediatr.Contracts in the application layer and then the full mediatr in the presentation (application root) layer.
@davidaltran8526
@davidaltran8526 Жыл бұрын
Great video! I have the same question. Why is Automapper considered external concern but not MediatR? Using MediatR for convience is a acceptable answer :)
@pilotboba
@pilotboba Жыл бұрын
@@davidaltran8526 Isn't mapping usually done in the Web project/layer? Map requests to commands and entities to responses ??? I guess I could see the entity to response mapping being done in the application layer. But not where I do it.
@dotnetMasterCSharp
@dotnetMasterCSharp 3 ай бұрын
Most useful videos, thank you Milan
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
Glad you think so!
@zakraw
@zakraw Жыл бұрын
Looks like I was implementing Onion Architecture instead Clean Architecture and I didn't know that. 😄
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
They're the same basically... 😂
@ramiroalegre8183
@ramiroalegre8183 7 ай бұрын
Hey Milan, i have a question about Onion Architecture, you created a Article entity in Domain project, and you used this entity in Persistence project with ArticleRepository, this is not a problem because you are using a Code First DB but what if i use database first? My Article will be created with properties based on my database columns (SQLServer, MySQL, etc). This is a problem, because my Domain will be depends of Persistence
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
You can either: - Use the scaffolded model, if possible, from the Domain (probably not possible) - Map from domain to "persistence" model - Add a DbContext that uses domain model, and can persist to DB?
@expertreviews1112
@expertreviews1112 Жыл бұрын
What about placing Automapper in Application layer? Doesn't that bind it with business logic? If at a later stage, another mapper or custom mapper is needed, it would require many changes to decouple old mapper and then implement new... Do you think it's better to have mapper in Infra ?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
The chances of changing a mapper are slim to none
@expertreviews1112
@expertreviews1112 Жыл бұрын
@@MilanJovanovicTech agree... They are slim but can't be ruled out... I had to recently replace Automapper with a more optimized mapper as my application was very large and Automapper was taking toll on memory... That's when I realized I needed Clean Architecture as Automapper was tightly engrained with every single project... Having it in Infra helps me as I can swap out very easily
@nosaanthony7310
@nosaanthony7310 7 ай бұрын
Thank you for this wonderful video. I have been using both architecture without having a clear understanding of the disticntion between the two architecture, and this video has cleared all grey areas. I noticed the Persistent project references the Domain project, is this allowed in clean architecture? My understanding is that only the application layer should reference the domain layer, but in your exmaple I see the "Article" object spanning across all layers up to the persistent/infrastructure layer.
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
IMO, they're the same thing 🤷‍♂️
@Zainjerr
@Zainjerr Жыл бұрын
Bro do you have any plans on making a videos series on an entire application from start to finish? frontend backend, db, containers, the whole 9 yards.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Yes, I did that in my course
@MahmoudSaed98
@MahmoudSaed98 3 ай бұрын
@@MilanJovanovicTech where can i find the course ?
@91-Orca
@91-Orca Ай бұрын
hi Milan, thanks for these details. are the hexagonal architecture and onion architecture the same ? what about ports and adapters architecture ? thanks
@MilanJovanovicTech
@MilanJovanovicTech Ай бұрын
I would say hexagonal is a bit "different" from an implementation perspective, more moving parts. But the result is pretty much the same, in terms of direction of dependencies.
@91-Orca
@91-Orca Ай бұрын
@@MilanJovanovicTech thanks. Hexagonal is the same as ports and adapters i think
@sunzhang-d9v
@sunzhang-d9v Жыл бұрын
The previous video was clean architecture? Adapters were replaced with Infrastructure
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Which previous video?
@joaocampos9615
@joaocampos9615 5 ай бұрын
Great video, Milan. Very practical info, rather to see your video to quickly be a up to speed, than reading a 500 pages Clean arquitecture book :P Thanks !
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
Glad you enjoyed it!
@pilotboba
@pilotboba Жыл бұрын
interesting. This is the first time I've seen anyone put the query handlers in the infrastructure (persistence) project. I've mostly seen the query handlers in the Application project which is also where the command handlers are. Do you see an advantage to putting them there?
@okito
@okito Жыл бұрын
the only real reason is that your application layer doesnt need a dependency on the ORM when handlers are in persistance/infrastructure
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Avoiding a reference to any persistence mechanism in the Application layer. And continuing down that train of thought, it makes sense. For a query I usually don't care how it's implemented, I only care about the result I get back. So I can move the details of that to Infrastructure. For command handlers, I definitely care about the implementation because it has business logic, so I want it in the Application layer. This is an idea I got from Jeffrey Palermo's Onion Architecture repo, and I just adapted it to MediatR.
@pilotboba
@pilotboba Жыл бұрын
​@@MilanJovanovicTech So your repositories implementation only have the queries needed for the command handlers? And your query handlers use EF dbcontext directly I assume? Frankly, though, I consider Queries a use case so prefer them in the UseCase (application) project. So many ways to skin the cat I guess.
@kostasgkoutis8534
@kostasgkoutis8534 Жыл бұрын
This goes very well hand in hand with the asymmetric approach DDD/CQRS follows. The write side of the application tends to be more strict and specific than the read side that can just fetch the data however it wants. Which would make the Domain project (Entites + Repositories) less significant for the read side.
@pilotboba
@pilotboba Жыл бұрын
@@kostasgkoutis8534Yes, I like the suggestion that there is a projection that matches each "view" in the UI so the query is nothing more than select * from CustomerSummaryView (or whatever) But, I've never got to this point.
@murat.yuceer
@murat.yuceer Жыл бұрын
If you separate application service methods by class then it changes from onion to clean right? :)
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
It's the same thing, either way you look at it. Using services doesn't change the architecture
@murat.yuceer
@murat.yuceer Жыл бұрын
Do you have example project without clean arch. I need startup template with onion like your paid project@@MilanJovanovicTech
@markokafor7432
@markokafor7432 Жыл бұрын
Nice video and explanation but there isn’t much difference based on this tutorial. Just naming and package, for the onion architecture you used services and EFcore while for the clean architecture you used command and mediatr.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
That was kind of the point ;)
@masoudmotlagh6384
@masoudmotlagh6384 Жыл бұрын
thanks for the video, how to access your sample codes? github?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Patreon or github.com/m-jovanovic
@ismailfedaoui6841
@ismailfedaoui6841 Ай бұрын
Thank you for the explanation, but I still don't see the difference. You've used MediatR in the Onion architecture, but not in the Clean architecture. Does using MediatR in the Onion architecture mean we've migrated to the Clean architecture?
@MilanJovanovicTech
@MilanJovanovicTech Ай бұрын
That's because... the difference is pretty much non-existent
@antonmartyniuk
@antonmartyniuk Жыл бұрын
Ah, after all you did this video! Nice!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Hope you enjoyed it!
@antonmartyniuk
@antonmartyniuk Жыл бұрын
@@MilanJovanovicTech sure, I enjoy watching your videos
@matthayden1979
@matthayden1979 Жыл бұрын
Can't we put entities and repositories outside of domain and create a 2 separate layers among them?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Yes
@matthayden1979
@matthayden1979 Жыл бұрын
@@MilanJovanovicTech Thanks! That won't impact the overall onion architectural style?
@matthayden1979
@matthayden1979 Жыл бұрын
@@MilanJovanovicTech Thanks! That won't impact the overall onion architectural style?
@wh33lers
@wh33lers 7 ай бұрын
I personally would argue that mediator is part of a framework. That is why I am not using it, because every usecase class will depend on that library in the end. And use cases should describe pure business logic. I get why it is very convenient, but are you not a bit hesitant regarding the hard dependency?
@MilanJovanovicTech
@MilanJovanovicTech 7 ай бұрын
No, not at all. Love using MediatR.
@microtech2448
@microtech2448 Жыл бұрын
Did you need AsNoTracking() while projecting response using select new in clear architecture example?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Nope
@khoalong8781
@khoalong8781 9 ай бұрын
Still using AsNoTracking while select immutable object. it's an indepence with clean architecute.
@PrashantShekher
@PrashantShekher 11 ай бұрын
Please explain too that Clean Architecture focuses on layering, while Onion Architecture focuses on inverted layering.?
@MilanJovanovicTech
@MilanJovanovicTech 11 ай бұрын
They're the same :)
@obedasante2168
@obedasante2168 Жыл бұрын
Apart from grouping features with folders what different thing does the clean architecture actually brings? It keep confusing me. Everyone implements it differently. I love onion. Simple and straight forward 😊😊
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
It's all the same thing, really...
@Moaaz-SWE
@Moaaz-SWE 5 ай бұрын
Does anyone knows why the clean architecture doesn't represent the repository (repo interfaces) in its diagram + I didn't understand the point of making a requestQuery class in the usecases then injecting the dbContext and implementing it in the infrastructure rather than just declaring GetArtictleByIdQuery method in the repo interface then implementing it in the infrastructure and using just like the other requests and request handlers in the usescases
@MilanJovanovicTech
@MilanJovanovicTech 5 ай бұрын
It's all about direction of dependencies. Both architectures can be interpreted and implemented in different ways.
@verbroez712
@verbroez712 4 ай бұрын
5:59 - IArticleRepository interface references your Api. Have a look at the top using statement. It's against either onion and clean architecture rules.
@verbroez712
@verbroez712 4 ай бұрын
The same thing with the service in the Application library project.
@MilanJovanovicTech
@MilanJovanovicTech 4 ай бұрын
No, that's just the namespace of the Article (which should be Domain.Entities though) 5:39 But the project references are correct. You can grab the source code and check (pinned comment).
@verbroez712
@verbroez712 4 ай бұрын
@@MilanJovanovicTech ok, that's make sense. Thanks for the video, bro.
@cancurva
@cancurva Жыл бұрын
Do you know any Java spring channel as good as this one ?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Nope :(
@pavelromashuk237
@pavelromashuk237 Жыл бұрын
I think Clean architecture is more complicated than described in the video. Some key points - bounded context, domain objects are missed. Domain objects are completely different in onion ad clean, in clean you can`t simply take domain object and save it.
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
You don't need to use DDD to work with Onion/Clean
@saddamhossaindotnet
@saddamhossaindotnet Жыл бұрын
Yeah! This is a good point.
@pavelromashuk237
@pavelromashuk237 Жыл бұрын
@@MilanJovanovicTech Yep, you are right, I messed up things.
@theundaddy8037
@theundaddy8037 10 ай бұрын
I think it is confusing to have a use-case (GetArticleById) in the application layer, where you only define the query and the response, and the developer is expected to know to implement the handler in the persistence layer. Wouldn't it be better to define a IArticleReadRepository interface, implement it in the persistence layer, and then implement the GetArticleByIdQueryHandler in the application layer, injecting the IArticleReadRepository into it?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
Having an IArticleReadRepository defeats the purpose of GetArticleByIdQueryHandler. The GetArticleByIdQueryHandler becomes a wrapper calling an interface method. What's the value in that?
@MilanJovanovicTech
@MilanJovanovicTech 10 ай бұрын
I made a video doing something similar: kzbin.info/www/bejne/iJjUdJSsi5eWp7M You can see how silly it becomes
@theundaddy8037
@theundaddy8037 10 ай бұрын
@@MilanJovanovicTech Thank you very much for the link! I agree, it does seem pointless to create all this unnecessary abstraction with read services, if all we are doing is running a simple query.
@pioners1001
@pioners1001 3 ай бұрын
Onion, Clean, or whatever are just branding of the same thing. The most important part of this is the concept, not the implementation details or the name. Implementation might diverge and adapt to your needs.
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
Yes, you're spot on. I wrote about this in a few posts recently.
@wmalgoire
@wmalgoire Жыл бұрын
Cool idea to explain differences between those two approaches👌The layer is thin.. 😁 On a personal note I'm so glad CleanArchitecture has become more popular. I'll always remember the face of the people I tried to explain/sell "Onion" architecture benefits. Lost half of them right at the beginning 🧅🤥
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Onion just sounds weird, that might be the problem 😅
@techpc5453
@techpc5453 Жыл бұрын
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
👋
@muhamotto2084
@muhamotto2084 Жыл бұрын
isn't supposed that the GetArticleByIdQueryHandler in the persistence layer uses the ArticleRepository instead of using the ApplicationDbContext ??
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Why would it?
@muthumanivelv566
@muthumanivelv566 Жыл бұрын
I thought both are one in the same🙄
@Forshen
@Forshen Жыл бұрын
Its the same, even the dotnet channel said it. "formerly known"
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
By the end of the video, you can come to that conclusion
@sotsch9280
@sotsch9280 Жыл бұрын
They are the same 😂
@expertreviews1112
@expertreviews1112 Жыл бұрын
why not shared source code? so inconvenient :(
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
I share it on Patreon
@MdFaisalMahmudShow
@MdFaisalMahmudShow 8 ай бұрын
Im little bit confused here. Onion focus on services and clean focus on use cases. But service contains the use cases, isn't it? Then What is the difference actually, Can anyone explain it.
@MilanJovanovicTech
@MilanJovanovicTech 8 ай бұрын
They're the same thing 😁
@MdFaisalMahmudShow
@MdFaisalMahmudShow 8 ай бұрын
@@MilanJovanovicTech 💔
@juliangzr4998
@juliangzr4998 Жыл бұрын
Thank you!
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
You're welcome!
@Forshen
@Forshen Жыл бұрын
Its the same, even the dotnet channel said it. "formerly known"
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
Formerly known?
@lettuceturnipthebeets790
@lettuceturnipthebeets790 Жыл бұрын
​@@MilanJovanovicTechthey probably meant dotnet channel mentioning Clean Architecture formerly known as Onion Architecture
@Forshen
@Forshen Жыл бұрын
I wanna add, that most design patterns (including architecture) are just a theory of how to do certain stuff. But its not a strict rule, so the Clean Architecture can be implemented with different outcomes.
@sunzhang-d9v
@sunzhang-d9v Жыл бұрын
Clean Architecture is not Domain-Driven Design?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
It seems not
@sunzhang-d9v
@sunzhang-d9v Жыл бұрын
How to make a DDD architecture?@@magashkinson
@sunzhang-d9v
@sunzhang-d9v Жыл бұрын
How to make Domain-Driven Design? @@MilanJovanovicTech
@sotsch9280
@sotsch9280 Жыл бұрын
You can combine both concepts easily
@truzhot
@truzhot 3 ай бұрын
Both are the same, the difference for me, is that one uses CQRS and another Services.. idk
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
Yep
@alibabarahaei2229
@alibabarahaei2229 6 ай бұрын
Perfect❤
@MilanJovanovicTech
@MilanJovanovicTech 6 ай бұрын
Thanks, glad you enjoyed it
@Spacchio
@Spacchio 3 ай бұрын
In clean architecure the repository belongs to the application layer not the domain. The use cases should be exposed as inbound ports of the app layer and they should not be commands, they could however be implemented underneath as commands, but that's a technical detail that the caller does not need to know. A use case should also be named as Use Case at the end, for example AddOrderUseCase to make clear we are talking about use cases and not services or bananas. All the external dependencies of the application layer should be defined in a separate project called application.ports.outbound which is the one that the external layers will implement.
@MilanJovanovicTech
@MilanJovanovicTech 3 ай бұрын
UseCase = Command/Query, same thing. "All the external dependencies of the application layer should be defined in a separate project called application.ports.outbound which is the one that the external layers will implement" - Too much work for not so much benefit. We'll end up with dozens of projects if we go down this route.
@Spacchio
@Spacchio 3 ай бұрын
@@MilanJovanovicTech not really the same thing mate. Commands and queries are a technical implementation of use cases
@matswessling6600
@matswessling6600 9 ай бұрын
a VERY simple project. Why not show how a real world project is implemented... That will give a much better insigts in the real problems that you never need to handle in such simple examples..
@MilanJovanovicTech
@MilanJovanovicTech 9 ай бұрын
Because the concepts get lost in the complexity of a large project, and you can't explain it all in a 10-15-20 min video.
@matswessling6600
@matswessling6600 9 ай бұрын
@@MilanJovanovicTech I dont think so. Obviously you vcannot write that system from scratch but you can show diagrams of it and show exampkes of real code. these kind of simplified examples doesnt really help. it just fools people.
@emrahyigit
@emrahyigit Жыл бұрын
Both architectures are trash and will be deprecated very soon anyway. But thanks for the video. (Liked)
@juliansegura5507
@juliansegura5507 Жыл бұрын
Interesting take... why do you say so?
@MilanJovanovicTech
@MilanJovanovicTech Жыл бұрын
They've been saying that for almost 20 years now.
@pilotboba
@pilotboba Жыл бұрын
Is it the architecture that's trash or the project organization? Code to interface not implementation is a pretty well-established OOP principle. That said, why is it "trash"? Objective evidence, please.
@sotsch9280
@sotsch9280 Жыл бұрын
Anyone saying this has no Idea imho! 😂 sorry, but this architectures keep the most basic and ever important keypoints. You will always have to deal with dependencies and layers. Have Met alot of people saying the same, watching their "architectures" and know whats their problem.. they are mostly beginners, although few of them programming for tons of years.
@hungngo2857
@hungngo2857 4 ай бұрын
nothing is trash when u really understanf the idea behind it
How To Use Domain-Driven Design In Clean Architecture
30:27
Milan Jovanović
Рет қаралды 112 М.
Fix Your Controllers By Refactoring To Minimal APIs
14:56
Milan Jovanović
Рет қаралды 44 М.
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 2,2 МЛН
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 22 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
Vertical Slice Architecture, not Layers!
46:24
CodeOpinion
Рет қаралды 125 М.
How to structure a .NET Solution (project separation & architecture)
13:55
Clean Architecture with NET 8
54:38
NimblePros
Рет қаралды 4,5 М.
Hexagonal, Onion & Clean Architecture
4:30
Drawing Boxes
Рет қаралды 61 М.
Clean Architecture With .NET 6 And CQRS - Project Setup
12:40
Milan Jovanović
Рет қаралды 242 М.
How to Implement the CQRS Pattern in Clean Architecture (from scratch)
17:36
Modeling a Domain With Domain-Driven Design From Scratch | DDD
19:10
Milan Jovanović
Рет қаралды 92 М.
How I Use The Generic Repository Pattern In Clean Architecture
17:15
Milan Jovanović
Рет қаралды 40 М.
Onion Architecture - Software Design Patterns Explained
11:57
Professional Programming
Рет қаралды 24 М.
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 2,2 МЛН