Clean Architecture Example & B…



The Clean Architecture is pretty popular and I’ve been asked a lot about it directly and indirectly. I decided to take a Clean Architecture Example (Template) and give my thoughts about where I see value in using it, in which context, and what I don’t like about Clean Architecture and/or how it’s organized, in practice.

🔔 Subscribe:

💥 Join this channel to get access to source code & demos!

🔥 Don’t have the JOIN button? Support me on Patreon!

📝 Blog:
👋 Twitter:
✨ LinkedIn:

Clean Architecture Solution Template by Jason Taylor

0:00 Intro
0:24 Clean Architecture
2:07 Template
4:14 Domain
5:41 Application
6:50 Infrastructure
8:05 Abstractions
9:20 WebUI
10:34 Vertical Slices

CodeOpinon:
Twitter:

source

This post was automatic generated with this wp-automatic-plugin

Complete Responsive Laundry Se… Previous post Complete Responsive Laundry Se…
How to Auto Publish Posts to S… Next post How to Auto Publish Posts to S…

45 thoughts on “Clean Architecture Example & B…

  1. As soon as I discovered your channel, I had to look for this video. Nothing frustrates me more than people blindly following whatever pattern is trending. Thanks for covering this topic.

  2. Finally I found a reasonable explanation. Everyone just trying to make us memorize Clean Arch. But no one tells what if I don't need CQRS or something like that?

  3. Efferon coupling and Afferon coupling. you need to find better words, these make no sense t me and i can’t even hear the difference.

  4. What you're saying makes a lot of sense. But isn't the reason for the IApplicationDbContext interface so that the Application layer can use the DbContext features without explicitly depending on the Infrastructure (outside) layer? i.e. Inverting the dependencies. I agree it sort of falls apart when the Application project references Microsoft.EntityFrameworkCore, among other things. I've seen some Hexagonal Architecture examples in Java but am new to Clean Architecture in .Net. It all sounds good on paper, but virtually every .Net repo I've seen so far has violated the principles in some way, at least as I understand the purpose of each layer, which I may be mistaken.

  5. I don't see that you should do a specific pattern, but live up to the principles as long as they serve your needs – being pragmatic. The rest is just project style. In the beginning I took a "template" and modified that to suite my needs. Now I understand the principles, where that template fails for me, and can do all from scratch – without the template

  6. A simple rule of thumb for designing DDD approach is never think about database, table's, ui etc. Focus on domain object and it's behaviour.

    Incorporating DDD in clean architecture is where we get lot of questions like which layer to place each stuff. After reading many articles on internet, it would put us on confusion.

    Example: few justify repository interfaces should live in domain layer. Few say it should be in Application layer. Few say avoid factories for creating domain instances. But practically I see factories are very useful in creating domain instances. Few say don't use factories and use builder.

    It would be great if software community creates a sample project to showcase how it should be done correctly with justifications.

    I am glad I learnt certain standards and practices to follow from microsoft eshoponcontainers project. But not getting certain answers from the software community like: how to achieve event sourcing and publish integration event to event bus while using microsoft asp.net identity?

    Is there any portal where all of the if's and why's are answered with justifications?

  7. Hi , thanks for taking out time to explain in detail. I've always wondered if CA was any use in small projects. Do you by chance have a repo to the approach mentioned in the video, something in the line of a sample project that demostrates the use?

  8. One thing that makes my head spin about Clean Architecture is that the diagram states that in the green layer you implement your gateway (repository) but a repository is related to a database, which in this diagram… is in the outer blue layer. So if I were to strictly follow it, it's telling me that I would need to create an abstraction between my repository and the database driver/ORM. Same goes for the controller, e.g. according to the diagram my mvc framework needs to live in the blue, but I should also have a controller in the green. What are your thoughts on this?

  9. All good n' all but: Opinions will be opinions. I get that people find some approach more useful than others, I get some ppl get "married" to certain technology or platform, all that is OK. The onl… ERASE Entity Framework!! NOW! incarcerate the maniac that came up with it, melt the key and pour salty water in the door lock!
    Besides it takes a lot of extra time with no added gain, and makes the boilerplate a horrible broken-rows mess. Who in his/her sane mind will prepare a whole application to be, not only DB agnostic (which I adhere, of course) but "automatically" deployable…. what comes next: auto-migration? What the million other approaches to persistence out there? are SQL based a must?
    I get people have to find some work to do at Microsoft these days, but c'mon! do something useful, like that time when you did MS Messenger, or BizTalk in the early 2000s, or SOAP and webservices… at least seamed that you cared…
    Be a professional: manage your entities! (Rant is over)

  10. Today I've watched about 7 videos on your channel, and I really like your ideas and approach because it is practical and rational. Thank you so much!

  11. I think what you're looking for is to have a package by bounded context (or feature – although feature is even smaller), then inside of it to have have DDD for that bounded context and hexagonal architecture. This way you have high cohesion.
    What do you think?

  12. I really like your opinion. I've been working on a huge platform and the code got bigger than what I expected and I started looking for ways to improve my architure.
    This makes me feel better because I felt bad using my formal architecture for small projects but as you say it’s just fine.
    But for this big app I’m talking about I really need a strict separation of layers because later we will be moving to microservices and we really need code that can be easily broken into smaller pieces.

  13. I was asked this question during job interview came here to know the answer. I'm not really good at definition of terms interview I think I screwed my interview. 😭😅

    Thanks you so much for the explanation.

  14. Another great video. To be fair, I think Uncle Bob specifically mentioned that architecture is about risk management etc (the "tension diagram" towards the beginning of the book) but more importantly that his 4-layer diagram is an illustrative example; that there could be more or less layers. I think it's tragic that so many "clean architecture" examples shoehorn an application into the 4-layer paradigm.

    Project triangle for the win. Figure out which corner matters least and choose the path accordingly. Taking the time to make a GOOD abstraction is always a step in the right direction for quality. Understanding project scope and not wasting time on abstractions that will never be relevant is always a step in the right direction for cost and time.

    Afterthoughts:

    Deployment matters. For you youngsters: there was a time when software had to work and be close to perfect by the time it went into production. Video games used to be distributed on cartridges and optical discs. Updates were not even a possibility, so abstractions would have been ridiculous outside the context of a reusable video game framework. There are still some systems that operate like that (non-IoT embedded devices etc).

    Check out the "when to use" section of the GoF Design Patterns book for the "Bridge Pattern" … if I recall correctly, it says you shouldn't use the Bridge Pattern when there's only going to be one implementation. The Bridge Pattern is basically two layers of Strategy Pattern organized by role and a perfect OG example of a clean 3-layer architecture; Inversion of Control employed to isolate application logic (i.e. the "Abstraction") from the drivers & frameworks layer (i.e. the "Implementation")

    #UseTheRightTool4TheJob

  15. I spent a ton of time following clean architecture like religion and always found its structure needlessly complex. I eventually found myself doing what's implemented in this video and never looked back. Thank you!

  16. I had the exact same reactions to just about everything you've covered here. I love the architecture, but this template is not great. I think I just lean into abstractions from the very beginning regardless of the size of the project (unless it's super tiny of course) because I have personally found more benefit over time than cost. The greatest cost I've run into over the years is uninitiated developers. I think the way you described the grouping of functionality falls under another uncle bob concept which is 'screaming architecture' and I fully agree with it.

  17. For more complex Projects why just not split verticaly, but add projects as layers too? Yes a lot of solution folders and projects, but much harder to make mistakes.

    I would like to work for models, handlers, validations, events from the same file… but you need much more discipline and for every team member to actually understand the problem.

  18. I also found the definition of IApplicationDbContext odd, depends on EF, only one implementation is possible. Great video, your website has great content too!

  19. I am a Java developer. To do Clean Architecture, I would prefer creating a multiple module Maven or Gradle project. The interfaces and classes related to the different levels of abstraction, e.g. Domain, Application, Infrastructure, Web are placed in their respective modules and the dependency among the modules are configured with direction pointing toward the center of the Clean Architecture circle. By doing this, you won't mistakenly create a reference to classes or interfaces residing in the outer layers.

  20. This sadly is a bad example of clean architecture which is why you don’t need to or should use it. I’m typing with one finger otherwise I’d happily go into why 😛

  21. Wow, finally someone giving a proper analysis to the Clean Architecture. Agree 100% on that Dbset dependency issue and also there's another one that I still didn't find resolved anywhere and that is the isolation of Identity. Having my own User class, how to isolate the domain objects used by Identity without referencing the library? Great video. Would love to see your approach and a concrete example of your solution to my questions.

  22. I suggest you read the book Clean Architecture and then tell us your opinion. One probably shouldn't judge something when they haven't even read about it from the original source. This template doesn't demonstrate the Clean Architecture.

  23. This is a great video. I've been experimenting with clean architecture lately but have never gotten a straight forward example of what it looks like. My current style of implementing it is based off my interpretations of snippets from other posts. What you've described is pretty darn close to how I implement it which is very encouraging and shows me that I'm not just crazy.

    The grouping of all the pieces in a single file is interesting to me. I can see how, for smaller projects it might be OK but even that small example you had made that file enormous which might be unwieldy. I definitely think for a larger project, it might be worth it to use a folder for each feature and put each class in it's own file so as to have smaller, more manageable files. Though I definitely see how that can lead to times where you're flipping back and fourth between lots of files when you're working with the whole stack

  24. Your videos are awesome!!! Thank you for the amazing real world approach to all things C#!! You take a real world approach which is very helpful compared to 99% of others which take a “proof of concept” approach.

    Please keep it up! Been watching your videos all night

  25. I disagree that the point of the domain layer is to have business rules. The domain layer is simply your core models, no logic. The application layer holds all the logic, in this pattern, the queries and commands. And I think that is a very clean separation

  26. Lets say that there are several features that need to reuse the same code. For example, feature CreateUser would have a part of code that crates default todo list and that looks same as CreateTodoList and you want to reuse it. Im curious how would you chain these features if both are wrapped into their own SQL transaction explicitly.

  27. the point is to get folks start with something mean to become bigger thing. when you bake the controller into the application you cannot reuse this project for a console application. the point to separating projects is that you can put any new UI technologies on top of the application project.

  28. Overall video was helpful. Appreciate!
    But your verticle slice implementation is breaking a fundamental rule of Clean architecture. In CA, the dependency should point inwards and not outwards! When you put controllers in Application layer, now presentation layer need to reference Application layer (ideally it should be other way around) to register those controllers to web host!

    And also all related things for each domain are in one folder, so I think it's already better to discover those things. Controllers are outside in other project, because that is presentation layer and there might be multiple presentation layer in real world using same application layer!

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

error: Content is protected !!