Clean Architecture With .NET 6 And CQRS - Project Setup

Поділитися
Вставка
  • Опубліковано 8 лип 2024
  • Get the source code for this video for FREE → the-dotnet-weekly.ck.page/ca-...
    ☄️ Master the Modular Monolith Architecture: bit.ly/3SXlzSt
    📌 Accelerate your Clean Architecture skills: bit.ly/3PupkOJ
    🚀 Support me on Patreon to access the source code: / milanjovanovic
    You've heard about Clean Architecture before? In this video, I'm going to show you how to set up the Clean Architecture using .NET 6 and CQRS with MediatR.
    How I Approach Clean Architecture Folder Structure
    www.milanjovanovic.tech/blog/...
    Join my weekly .NET newsletter:
    www.milanjovanovic.tech
    Subscribe for more:
    ua-cam.com/users/MilanJovano...
    Chapters
    0:00 Introduction
    0:19 What is the Clean Architecture?
    2:51 Domain layer
    5:01 Application layer
    7:26 Infrastructure layer
    8:25 Presentation layer
    12:02 Outro
  • Наука та технологія

КОМЕНТАРІ • 420

  • @MilanJovanovicTech
    @MilanJovanovicTech  Рік тому +8

    Master the Clean Architecture: bit.ly/3PupkOJ

    • @lukagolubovic3641
      @lukagolubovic3641 Рік тому +1

      Quick update to the people, now after 3 months of releasing highest quality content, there are 4873 .NET engineers receiving those amazing tips (including me)

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      @@lukagolubovic3641 4961, forgot to update the website. 5k before #014 goes out, hopefully 😁

    • @nikitalingyt4837
      @nikitalingyt4837 7 місяців тому

      Hello, I'm new to your channel. Do you have a project on Git that I could check out?

  • @sushilb7994
    @sushilb7994 Рік тому +8

    Wow! I'm glad you started the UA-cam channel.
    I was always wondering how to avoid referencing all the layers into web project and your explanation helped to isolate into different project and register in the web. Excited for the entire series!!! Looking forward to the next video!!!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +2

      Thanks! I'm glad you liked this one. The coming videos will be much more practical (and useful), but I needed to set the stage somehow with this one.

  • @NavedDeshmukh
    @NavedDeshmukh Рік тому +6

    The idea for separating the presentation layer from web is genius. Glad learned something new today. Thank you for sharing.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I'm glad you liked that idea 😁

    • @RoyZASTEROiD
      @RoyZASTEROiD 11 місяців тому

      @@MilanJovanovicTech i cant understand purpose of seperation 'Controller'. Can you please explain me more in plain english or more in easy to understand language. Thanks

  • @danimydev
    @danimydev Рік тому +3

    Nice, I use Node JS thought but this content its pure gold, not many channels have videos on how to implement clean arch. Keep rocking!

  • @timcesar1
    @timcesar1 Рік тому +1

    Thanks, Milan looking forward to watching the whole series about this exciting topic

  • @pedroalexandre157
    @pedroalexandre157 Рік тому +4

    Great video quality! I'm sure your channel will grow exponentially, it's just a matter of time! Keep up the good work!

  • @angelldark6426
    @angelldark6426 Рік тому +2

    I learned how to use folders (model, core, helper, config, context, dbContext, migration, service) and create new libraries (I connect them through Project Reference). After your video, I realized that I still have a lot to learn.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      There's always more to learn, and that's a beautiful thing :)

  • @hamitkarahan2973
    @hamitkarahan2973 Рік тому +1

    Congrats Milan! I believe we have many things to learn from you. Keep going ✌💪

  • @saddamhossaindotnet
    @saddamhossaindotnet Рік тому

    Well done Milan! Congrats for your second video!

  • @trxe420
    @trxe420 Рік тому +4

    It is so nice that things have evolved to a point where we have good name for this now, I have been doing this for years and years and it was really just a collection of design patterns at the time. My favorite thing about it has to be the separated interfaces pattern, I really like having implementations in the infrastructure and the interfaces in the domain. I like the way you think about this and your presentation, you have earned my sub.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Hey Tommy. I do have a question for you. How do you group your entities in the Domain layer?
      I showed an example here where all of them are under the Entities/ folder. But I've gotten some pushback on this approach in favor of grouping by feature/context.

    • @trxe420
      @trxe420 Рік тому +1

      @@MilanJovanovicTech honestly it depends on the app, but for a large enterprise app I favor by context, improves maintenance imo. For microsevices that makes less sense imo.

  • @MKayJay
    @MKayJay Рік тому +8

    Finally, someone that actually cares about seperating the 'Configuration' from the presentation- I've been arguing this for quite a while among colleagues and friends- Finally nice to see someone agreeing, and actually having a good case where it makes sense! - Also nice quick overview of Clean Architecture- Thanks :-)

  • @waverider995
    @waverider995 Рік тому +1

    Awesome video! Can't wait for more videos about Clean Architecture!

  • @dennispitadeniya2479
    @dennispitadeniya2479 7 днів тому

    I'm new to clean architecture, and your video helped me to get the basics pretty quick.

  • @futurenerd2151
    @futurenerd2151 Рік тому +1

    Using Repository and UoW abstraction, I love that approach because it gives some benefits

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I agree, but some people seem to hate them 🤷‍♂️

    • @futurenerd2151
      @futurenerd2151 Рік тому

      It's a never ending debate, but if it serves a purpose then we should use it. End of discussion 😃

  • @drm1983
    @drm1983 Рік тому +1

    Excellent tip on the controllers Assembly. Good stuff!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Thank you. It's unfortunate how unfamiliar people are with this.

  • @wvanlosser
    @wvanlosser Рік тому +5

    Great video, I hadn't seen other examples of moving the controllers to a different project, learnt something new! :)

  • @mohamed-hassan-
    @mohamed-hassan- Рік тому +1

    such an amazing simplified video, thanks a lot (from a junior perspective)

  • @ryanalexander5438
    @ryanalexander5438 Рік тому +1

    Awesome work Milan!

  • @Felipe-ln1de
    @Felipe-ln1de 16 днів тому

    I liked how the WebApplication with the Clean Architecture really stands up for its name, It's less complex and more organized to create, maintaing and scale. Liked a lot!
    Im watching your vids to study and it's really helping me in my university's work

  • @impressias975
    @impressias975 Рік тому +2

    Thank you Chris. I really appreciate it and that was exactly what I was trying to do. No fuss and helping people get on with what they need

  • @rhiguera75
    @rhiguera75 Рік тому +1

    Great video. Go on!!! Architecture is a very important topic in sotware discipline. Your examples are simple but cover the important concepts in way that is simple to understand. Good job!!!!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I'm planning to expand on this in more detail in the future videos. We'll also cover some other architectures, I personally really like Modular Monolith.

    • @rhiguera75
      @rhiguera75 Рік тому +1

      Modular Monolith. rocks!!!!

  • @lucasluizss
    @lucasluizss Рік тому

    Well done Milan! Congrats 👏🏽👏🏽👏🏽

  • @SuperSayiyajin
    @SuperSayiyajin Рік тому +1

    Thanks...We wait for next videos.

  • @runawayvon01
    @runawayvon01 6 місяців тому +7

    As a member of your Patreon,
    I learned the basics of CQRS and how to build minimalist API.
    Because of this, I got the job offer from my new work.
    Thank you.

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      You are crushing it, congrats! 🔥

    • @dddanielsr
      @dddanielsr 4 місяці тому

      Can you share where and how did you apply?

  • @SysMess0
    @SysMess0 8 місяців тому +1

    Clean explanation for clean architecture, thank you milan for such a great video

  • @fernandocalmet
    @fernandocalmet Рік тому +1

    Very grateful for your content, the best successes Milan😁

  • @subashbarik
    @subashbarik Рік тому +1

    Great video , please keep posting videos like this.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Next video is coming out today - how to add DDD to the Clean Architecture

  • @omerkulahli3865
    @omerkulahli3865 Рік тому +1

    Great video! Thank you for sharing with us.

  • @HM_Milan
    @HM_Milan 10 місяців тому +1

    Thank you

  • @oimarrom
    @oimarrom Рік тому +1

    Tks for vídeo ! Hug from Brazil

  • @adriano.digiere
    @adriano.digiere Рік тому +1

    Great video Milan! Thank you so much for sharing.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Thanks, I'm really happy you liked it. What was your biggest takeaway from this one?

    • @adriano.digiere
      @adriano.digiere Рік тому +1

      @@MilanJovanovicTech Your explanation about why to define controllers outside the web application project was pretty good. I will apply this concept in my job. Thanks.

  • @darielamoresfernandez5491
    @darielamoresfernandez5491 Рік тому +1

    Great video!!! Thanks for sharing.

  • @alexmadnix
    @alexmadnix Рік тому +1

    Respect my bro

  • @vm7738
    @vm7738 Рік тому

    Thank you!

  • @milicabozic3827
    @milicabozic3827 Рік тому

    Interesting topic 🙌

  • @willemmeints3123
    @willemmeints3123 Рік тому +2

    You have a neat setup for the project. One thing I would change is where the commands are defined. I'm using event sourcing, so I have a strong relationship between domain events and my entity. I send commands to my aggregates that get translated to domain events. Because I'm using this pattern, I like to keep the commands and the events close to my aggregate.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I never worked with ES so not sure if that makes sense or not 🤔

  • @phanuwatwattanapraya7998
    @phanuwatwattanapraya7998 Рік тому +1

    Great video

  • @milosmaljenovic4670
    @milosmaljenovic4670 Рік тому +1

    Ajde da te pohvalimo i na srpskom :) Pratim te već nekoliko meseci na LinkedIn-u i zaista sam uvek uživao čitajući tvoje objave u vezi sa kodiranjem. Ovo je sada next level i svaka ti čast. Odličan video i super objašnjavaš. Želim ti puno uspeha sa ovim kanalom i jedva čekam sledeći video. Poz od bivšeg kolege iz HTEC-a :)

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Hvala puno Miloše! Jako mi je drago da ti se dopada video. Ja još uvek vidim tu puno prostora za napredak, tako da očekuj da će samo biti sve bolje sa vremenom. Zašto bivši kolega? Šteta. 😁

    • @milosmaljenovic4670
      @milosmaljenovic4670 Рік тому

      @@MilanJovanovicTech Naravno da ima ali za pocetak sve je super :) Htec je zaista super firma i stvarno je pamtim po svemu lepom, ali ukazala mi se prilika i ponuda koju nisam mogao odbiti, tako da sam nastavio svoju karijeru u drugoj firmi :) Srecno sa ovim kanalom i samo tako nastavi. Poz

  • @jaydeeppatil9120
    @jaydeeppatil9120 9 місяців тому +1

    Great Job

  • @shashankpandey1019
    @shashankpandey1019 Рік тому +1

    Great video 👍 thankyou

  • @mozamilahmadafghan4889
    @mozamilahmadafghan4889 Рік тому +1

    Thanks for this video, that helped me alot.

  • @alexmbr
    @alexmbr 8 місяців тому

    About controllers outside of the web project... You could handle the dependency injection inside the infrastructure and make the web project to reference only the infrastructure. That way you would be able to have the controllers inside the presentation web.

    • @MilanJovanovicTech
      @MilanJovanovicTech  8 місяців тому

      You'd still need to reference Infrastructure from the Api and the same problem happens

  • @petewarner1077
    @petewarner1077 Рік тому +2

    Very neat video, Milan, presenting some nice ideas like separation of presentation logic from the host application, and validation as middleware!
    I wonder why you choose to define IRespository and IUnitOfWork in the domain layer though?
    For me, this polutes your domain with concerns that start in the application layer. A tell-tale sign is when you start to see Task or ValueTaskT> in the domain - we're starting to leak IO concerns into our domain.
    Another way of looking at it - no logic in your domain is dependent on these abstractions. If you deleted them the domain would still build. It's a sign to move them outwards.
    I look forward to seeing more of your ideas here!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Thanks Pete! I like to define the repository interfaces there as a sort of convention. There isn't any practical difference if they were defined in the Application layer.
      But for Task in Domain layer, I tend to not shy away from this. Yes - I am introducing impurity in the domain. This is usually through double dispatch, which I often use. I find that this is easier for testing purposes, and keep the Domain pure from Task doesn't yield any actual performance benefit. You would still perform the IO call one layer up.
      I guess it comes down to how comfortable you are with using Task in the Domain, and how you approach modeling the Domain in general.
      At the end of the day, both of our approaches will work the same.

    • @petewarner1077
      @petewarner1077 Рік тому +1

      @@MilanJovanovicTech Task in the domain is the lesser problem here - it's the presence of IRepository and IUnitOfWork.
      You say you put them there by convention and it wouldn't be any practical difference to move them out to the application layer. But consider your motivation for separating the presentation layer from the infrastructure layer to prevent a developer being able to access infrastructure concerns.
      To me this is a very similar context - what's to stop a developer who doesn't yet comprehend what the domain is for from deciding to include a LoadAsync method on a domain entity and pass in IRepository because they saw it in the domain and thought it must be used there?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      @@petewarner1077 That would be tragic indeed. I will honestly have to ponder on this to see what conclusion I come up with. Maybe I end up moving it to the Application layer. 🤔

    • @cansozbir
      @cansozbir Рік тому +1

      @@MilanJovanovicTech I wonder what do you think about this topic today Milan :)

  • @ricomarcelo5521
    @ricomarcelo5521 Рік тому +1

    thanks! subbed.

  • @stunna4498
    @stunna4498 Рік тому +5

    My main problem with CQRS is that i will have to code alot for simple things. If i need to add something i would need to see in detail where this interface is because its deep down the commands or w/e.
    So i do a mixture of clean architeture with the normal 3 layer and i normally have the infrastructure layer with my repo, external services(email etc) and my application layer would only deal with the business logic using the repos interfaces(contracts) to persist data.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Of course, that's a great way to implement the Clean Architecture 😁

    • @darrenadams783
      @darrenadams783 9 місяців тому

      I work in a similar way.
      I think the key is to pick what works for you. There is no "correct" way to do it.

  • @Cursix
    @Cursix Рік тому +1

    Good video

  • @balajisairamnarasimhan
    @balajisairamnarasimhan 11 місяців тому +1

    Thanks for posting this video and making this clear architecture more precise. Can you pls mention the benefits of using these pattern versus others ?

  • @ertugrulkayabas7157
    @ertugrulkayabas7157 Рік тому +1

    I lke it :) Thank you

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Awesome! There's a whole series of videos on this topic coming

  • @codewithguillaume
    @codewithguillaume Рік тому +1

    Dear Milan! I have so much trouble with clean archi. I really think it’s difficult to handle, difficult to maintain especially with teams nowadays that are a lot composed by juniors 😅 but thank you very much for this video. I’ll dive deeper into it !

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Why do you find it difficult? What part is the most problematic?

  • @swiftybathero
    @swiftybathero Рік тому +44

    Hi Milan,
    I like the "trick" of separating the Presentation layer from the composition root. But there are also two things that I'm not so sure about:
    1. Don't you think, that persistence-related abstractions, like IRepository and IUnitOfWork should be placed in the Application layer, instead of the Domain layer?
    I think that the Domain layer shouldn't know anything about the persistence, even if it's only a contract. In fact, the Domain layer doesn't have to know if it's persisted at all :)
    2. Some persistence logic in your QueryHandler in the Application layer - shouldn't we move it to the Infrastructure layer?
    Persistence logic is in fact something related to external dependencies, so you're breaking the idea of separating the Application layer exposing interfaces from the Infrastructure layer containing implementations related to all external concerns.
    Also, I would consider making your Application layer more explicit and using Result monads instead of relying on middleware from the Web project to catch everything and translate it to a proper response code. This is not entirely bad, but at least opinionated in the community : )

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +25

      Thank you for this brilliant comment! Let me address each point.
      1. I don't think this is the case. I look at the repository as a "contract" of what you are allowed to read from the Domain layer. I don't use the repositories on the query side. So the repository for me is a contract of: here are the entities you can read, here is what you can do with them (add/update/remove), and here's how to commit the changes (unit of work). The repository is just an abstraction. In that sense, I find that it doesn't pollute the Domain layer.
      2. I agree with this. This was a naive example, and I probably should have used something more robust. I will cover implementing the Application layer in a future video, and on the Query side, I want to show how to abstract data access completely.
      3. I covered the Result object approach in my latest video "Domain Validation with .NET". I plan to use this approach going forward, so we are aligned on this one.

    • @ucheemmanuel9797
      @ucheemmanuel9797 Рік тому

      How can I reach you? Would love to learn

    • @offthepathworks9171
      @offthepathworks9171 Рік тому +1

      Brilliant discussion, thanks to both.

    • @jakkepiet
      @jakkepiet Рік тому +2

      @@MilanJovanovicTech I've seen both use cases to place the repositories interfaces in the domain and application layer. And in my experience, it depends. If the repository is as true to the pattern as possible, it belonging into to domain layer makes sense.
      As for the Result object vs Exceptions, it also depends. In some message driven applications using something like nServiceBus or MassTransit using exceptions is very usefull.
      In Rest based services/front end facing services, using a result object can make more sense.
      But sometimes a domain exception is used like a comuflaged goto statement.
      In my current project, errors are handled as domain exceptions, except for in our BFF applications, were the domain exceptions are translated in something more atune for the front-end

    • @danfriedman7009
      @danfriedman7009 Рік тому

      @@jakkepiet I put my repository in a SharedKernel project that every bounded context depends on. This project is a bunch of contracts, like IRepository, EntityBase, IAggregateRoot and other commonalities between BCs.

  • @jeraxsanchez
    @jeraxsanchez Рік тому +1

    New subscriber here. Thank you

  • @darielamoresfernandez5491
    @darielamoresfernandez5491 Рік тому +3

    Hi Milan. I'm a Cuban developer that follows you since the beginning of your work on LinkedIn. I'm very interested in this topic and these videos I will be happy to support you on Patreon to get access to your code. But Patreon is blocked for Cuba and I can't use a popular method of payment cause we don't have Visa or Mastercard. If you have another platform that supports crypto payments to support your work it will be great. I will start a new project in my actual job and I wish to have this code for better understanding. Thanks for sharing your knowledge with the community and made this awesome job. Keep doing it.

  • @vijaysaini83
    @vijaysaini83 Рік тому +2

    Hi Milan, Just a feedback that there should be a beginner series as well. Its really not easy for beginners to start learning from your videos, specially me who started just few days back.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      That's fair! I'll work on that in the future :)

    • @yevheniimolodtsov9510
      @yevheniimolodtsov9510 11 місяців тому

      Just to point out here - architectural design patterns is not something you learn having a few days of experience in programming. Those concepts require some maturity and background in the spehere

  • @fieryscorpion
    @fieryscorpion Рік тому +2

    Great video!
    Can you please please show how to setup Serilog logging in this project structure throughout all the projects?

  • @VijayNirmal
    @VijayNirmal Рік тому +2

    Great video. Just curious,
    1. Have you used this pattern in large team?
    2. Where the new team members able to pick up the code easily?
    3. Everything has downsides, what are the downsides of this Architecture in your opinions?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      1. Depends what you consider large? I used this in a 10 man team, and it scaled very well.
      2. That was actually the biggest compliment they had - it was very easy to get up and running, and start contributing.
      3. Too complex for simple CRUD apps, so choose wisely

  • @sys-zr8ve
    @sys-zr8ve 5 місяців тому

    Hello Milan, I enjoy watching and learning from your educational videos! :)
    Would be very nice with a Github repository for each video.
    Pozdrav

  • @sudhirpatil8217
    @sudhirpatil8217 Рік тому +1

    This introduction part is great. KUDOS TO YOU...
    Where is the next video for implementation part ???

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Check out this playlist: ua-cam.com/play/PLYpjLpq5ZDGstQ5afRz-34o_0dexr1RGa.html

    • @sudhirpatil8217
      @sudhirpatil8217 Рік тому

      @@MilanJovanovicTech yes I am going thr that immediately after this video....
      G8 content

  • @adeni4359
    @adeni4359 Рік тому +1

    Subscribed! Please post more videos, like Web Api

  • @maroquio
    @maroquio Рік тому +2

    Hello, buddy. Congrats for the video! Any special reason to use .NET Core 5 instead of 6? Or, are you using 6 with a startup class?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Hey Ricardo, this is .NET 6 actually. I just used a project with Startup/Program class. The other examples moving forward will be with minimal startup approach. 😁

  • @DasturlashniOrganamiz
    @DasturlashniOrganamiz Рік тому +1

    Thanks for great video. I have a question on CQRS Pattern. The business wants me to implement Upsert feature. I need to first READ and then WRITE based on the retrieved object. Is it going to be command or query?

  • @gremlinx7819
    @gremlinx7819 Рік тому +4

    Great channel! Few questions though :) Are there any plans to create and share maybe one git project for this that will follow these tutorials? Also, would it be possible to show in one of the next videos an example of how third-party integration should be done with this type of infrastructure, for example, simple integration with email sending service? Cheers

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Thanks for the questions, let me address them one by one.
      1. The source code is currently available for my Patreon supporters. However, I do have some more involved examples on my Github: github.com/m-jovanovic
      2. Yes, that's a great idea. And I will definitely go over an implementation like that, email seems to be the simplest approach.

  • @LeonardoGSena
    @LeonardoGSena 4 місяці тому

    Absolutely amazing! I'm wondering what theme you're using... could you share? Tks!

  • @MrAymenmatador
    @MrAymenmatador Рік тому +1

    Great video keep it up.
    I just have one question as a beginner with clean architecture : why Application layer contains use case implementation ? what if we want to change db implementation, aren't we supposed to just alter the implementation with the new one without modifying the core ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      The use cases should ideally depend on abstractions only. That way, you only have to change the abstraction implementations and the Core would remain unchanged.

  • @msayeed78
    @msayeed78 Рік тому +1

    Great Job!! keep it up. I have a question how can we use database stored procedures in clean architecture, some of my business logic is in stored procedure. Thanks in advance for your valuable advice.

  • @alwaseem5309
    @alwaseem5309 10 місяців тому +1

    TO START WITH, Great content, and thanks.
    What if someone does not like to use CQRS. What will the controller use to send (query) to eventually hit the DB? Is Repo pattern a solution? Or do you have any advice?

  • @sunilanthony17
    @sunilanthony17 Рік тому +1

    Hi Milan, I'm a bit confused. How do you add dependency injection for your DBContext? Won't it break Clean arch pattern if you reference the DBContext in your web application?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      I do it through interfaces so that my Application layer doesn't reference the DbContext

  • @natiwl
    @natiwl Рік тому +1

    Nice simplified Video,
    Just a question, why did you use parameterless constructor in Webinar class?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      For EF Core, so that it can initialize the entity when querying

  • @ZhangJay
    @ZhangJay Рік тому +1

    Is it better to have a Service Layer to handle complicated update commands logic?
    and define the service abstracts in the Domain Layer.

  • @branislavpetrovic7486
    @branislavpetrovic7486 Рік тому +5

    Great video Milan! I have 2 questions:
    1) Why Dapper is used in Application Layer(which is part of Core) if our Core should be independent of libraries and frameworks? Would be a better approach if we use 2 separate interfaces for read/write (IReadRepository, IWriteRepository) and implement them in Infrastructure layer (e.g. EF for write, Dapper for read)?
    2) What is differences between Domain services and Application services when we not following CQRS approach, and could give some short examples of both?
    Thanks!

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +6

      1. I don't think SQL (Dapper) is as heavy a dependency as EF is. I can also easily mock the call to IDbConnection. With EF it's quite difficult. I will cover an approach in a future video for completely "cleaning" up the Application layer from all external dependencies.
      2. Domain Service is defined in domain, and so all it's dependencies also have to be Domain concepts. It's usually a blurry line between Domain/Application service. What I usually do in Domain service is when I need to manipulate more than one entity, but there is not natural candidate for an "Aggregate root" - then I introduce a Domain service. For Application service, it's the same as Command/Query handlers.

    • @branislavpetrovic7486
      @branislavpetrovic7486 Рік тому +1

      @@MilanJovanovicTechThanks for nice clarifications. Keep going with nice work.

  • @MrJonnis13
    @MrJonnis13 Рік тому +1

    Thank you Milan, really informative.
    Just a question, isn't the private field in 10:01 able to work also in the case ?
    The compiler does not complain. Or if you would build the project it would complain?
    What projects are you reference in the Presentation layer?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      It would fail at compile-time, there isn't a reference to the project where it's defined.

    • @MrJonnis13
      @MrJonnis13 Рік тому

      @@MilanJovanovicTech Makes sense!
      Thank you for the clarification :)

  • @rossimac
    @rossimac Рік тому +1

    Hi Milan, I see in your LinkedIn that you have Clean Architecture, CQRS and RabbitMQ. In my company, we use NServiceBus with RabbitMQ as the transport. My question is: where to place the NServiceBus message handlers? Currently, we have them in the Presentation layer. I believe we should put them in the Infrastructure layer and then use the Application layer to carry out the tasks. Would be very keen to hear your take on how you've done it in the real world.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      We just place them in the Application layer, since they will contain business logic usually. Yes - this does introduce an external dependency in the Application layer but it's a tradeoff we made.
      Your approach also works fine.

    • @rossimac
      @rossimac Рік тому +1

      @@MilanJovanovicTech Thanks Milan. By the way, your channel is fantastic and is an inspiration to get more into DDD. Thanks and I wish you all the best with it and your career.

  • @Zisane21
    @Zisane21 3 місяці тому +1

    I may have missed this but what layer should Errors\Result be part of? In another video saw you used a SahredKernel project

    • @MilanJovanovicTech
      @MilanJovanovicTech  3 місяці тому

      Domain/Common/SharedKernel - not so important. What matters it that it's somewhere where other layers can reference it. In this case, it's the Domain. In another video, I moved it into SharedKernel.

  • @shabbir200
    @shabbir200 10 місяців тому +1

    Hi Milan,
    I have been following lot of your videos specifically Clean Architecture one's, Really like you present them in separate videos. Just have one query you define project setup, Repository pattern, CQRS using clean architecture but is there a video where you call controllers / endpoints via Web projects ?
    Thank you for great help, keep posting new videos :)

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 місяців тому

      Try this video: ua-cam.com/video/nE2MjN54few/v-deo.html

    • @shabbir200
      @shabbir200 10 місяців тому

      @@MilanJovanovicTech Thanks Milan much appreciated for that video. How do you get the Carter is there nuget package also if possible can i access the Git Repo for this Crud example would like to view how to register services
      Thank you

  • @helloworld9018
    @helloworld9018 2 місяці тому

    Good day, Milan. When should one consider using clean architecture? I suppose when project is really big and must be built with the aim to the future? It seems to me that for small projects it would be an overkill.

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 місяці тому +1

      www.milanjovanovic.tech/blog/why-clean-architecture-is-great-for-complex-projects

  • @tesszheng4586
    @tesszheng4586 Рік тому +1

    Is it really a good practice directly use sql syntax when querying Webinar By Id, shouldn't it use the same approach as Creating Webinar through IWebinarRepository, and leave the implementation of WebinarRepository inside Infrastructure?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      It's not "clean" in terms of Clean Architecture, but it's not wrong from a technical perspective.

  • @rakeshkrishnan7729
    @rakeshkrishnan7729 Рік тому +1

    @Milan this design keeps interfaces on domain layer and its implementations on infra right? When your application grows you infra layer will be end up in having tones of business implementations at that point does it really possible to change to any other persistence technology without major impact as the clean architecture promoting this as it's major benefit?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      You can switch the implementation. Why would you place the business logic in the repository implementation though?

  • @jchandra74
    @jchandra74 Рік тому +1

    Good talk. Is there any github repo for the example that we can look at more in depth?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      I share the code with my Patron supporters.
      But you can also see a nice example on my GitHub.

  • @subhrajitmazumder7122
    @subhrajitmazumder7122 20 днів тому

    @Milan Awesome. Very helpful for beginners like me who want to create a project setup based on clean architecture. But as a beginner, I have a question.
    In the above example we find that for the interfaces, the infrastructure layer has the reference of the domain layer to access the repository interfaces for implementation. That means the infrastructure layer gets the reference of the domain layer. But in the clean architecture diagram, we find that the infrastructure layer should depend only on the application layer. But here to access the repository interfaces we need to add the reference of the domain layer inside the infrastructure layer. Is this the correct approach? Or we add the repository interfaces inside the application layer? Please clear my doubt.
    Thank you,🙏

    • @MilanJovanovicTech
      @MilanJovanovicTech  20 днів тому

      Outer layers can reference inner layers

    • @subhrajitmazumder7122
      @subhrajitmazumder7122 20 днів тому

      @@MilanJovanovicTech If the outer layers can reference the inner layers, that means infrastructure and persistent layers also can access the domain layer ? Also I have a question, can we move the Interfaces folder from domain layer to application layer? As per my thinking, then infrastructure and persistent layer only depend on the application layer. Is this the correct way? Please help.
      Thank you🙏

  • @osamadammag6303
    @osamadammag6303 10 місяців тому +1

    Hi Milan
    I have a question ⁉️
    Solution explorer has many known layers except docker.compose could u tell me how to create it and what it does !
    Thanks

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 місяців тому +1

      You can create it directly from Visual Studio with Add > "Container Orchestration Support"

  • @andreibicu5592
    @andreibicu5592 7 місяців тому

    Hi Milan.
    Nice video as always.
    I wonder why do you store the interfaces for the repositories in the Domain project, if they are only used in the Application project and the concrete classes reside in Infrastructure project ?
    The same question for other parts of the Domain that are never referenced in the Domain project.
    Thanks!

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 місяців тому

      I consider repository interfaces part of the Domain, as they only work with Domain entities.

    • @andreibicu5592
      @andreibicu5592 7 місяців тому

      I see your point, but everything revolves around the Domain. It doesn't mean we put everything into the Domain.

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 місяців тому

      @@andreibicu5592 These are just the interface definition. It's my view on how things should be done. Doesn't mean it's the only way.

  • @SOYLUISO
    @SOYLUISO Рік тому +1

    suscribed! what about .net minimal api and clean architecture? great video by the way!

  • @DasDreaD666
    @DasDreaD666 Рік тому +1

    What if database is responsible for generating Id for newly created resources? Do we completely remove the parent Entity class? How does it look in DD approach?

  • @ealeykin
    @ealeykin Місяць тому

    Hm, nice explanation of how you can make super simple project to look super complex

  • @carlosbolivar3508
    @carlosbolivar3508 9 місяців тому

    Hi Milan, this is great video! tahbk you!!, I just wondering if you have a git repo with this project?

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 місяців тому

      You'll find some nice examples here: github.com/m-jovanovic

  • @ramytawfik9168
    @ramytawfik9168 Рік тому +1

    one question please Milan.
    How do abstraction Layers affect performance as you said in Query Handlers?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      It's not significant, I have a video about it coming out today.

  • @dallyoluwafemi2827
    @dallyoluwafemi2827 Рік тому +1

    Thanks boss, do you have videos of how you build the applications you do use for examples
    please help a beginner

  • @warrenbuckley3267
    @warrenbuckley3267 Рік тому +1

    Where would you put stuff for cross cutting concerns (common stuff). Like, say you have some helpful string extensions methods, where would these "helpers" go?

  • @maxaigner5322
    @maxaigner5322 6 місяців тому

    so if we draw the analogy to a MVVM project, could we say, that the Model is the Domain, the ViewModel is the application and the View is in the presentation layer, right?
    And the Infrastructure would be stuff like internet services, themperaturedata from RS232, whatever and maybe also a Data Access Layer for File storage?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 місяців тому

      Why should we compare a design pattern to an architectural approach?

    • @maxaigner5322
      @maxaigner5322 6 місяців тому

      Hi​@@MilanJovanovicTech, thanks for your perspective! I agree that it's not always straightforward to compare a design pattern like MVVM directly with an architectural approach like Robert C. Martin's CLEAN Architecture. However, my goal is to understand how the components of MVVM, which I've used in my code structured around CLEAN principles, map onto the different parts of CLEAN Architecture. I find the analogy helpful because both approaches essentially partition code responsibilities in a similar manner. It's really about leveraging the strengths of MVVM within the CLEAN framework to better organize my existing code.

  • @malikehsan147
    @malikehsan147 Рік тому +1

    Do you have any official documentation links available for MediatR and CQRS?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      The MediatR documentation is a good place to start - other than that, I will be creating a video on that topic very soon.

  • @danielbahe
    @danielbahe Рік тому +1

    There is any advantage (apart of code reuse) to split in projects instead of folders?
    So you can split by functionality/module and then by every layer of Hexagonal architecture.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      If you split in projects you can hide details with the internal keyword

    • @danielbahe
      @danielbahe Рік тому

      @@MilanJovanovicTech So could be a good idea to create a project folder strcture like this?:
      ModuleName.csproj -> Infrastrcturure (folder), application (folder) domain (folder)

  • @elpe21
    @elpe21 Рік тому +1

    Would be nice have source code available showed on the video ;) Thanks for the video. going to watch others

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      At the moment, the source code is only available to my Patreons.
      But you can find some nice examples on my GitHub.

    • @elpe21
      @elpe21 Рік тому

      @@MilanJovanovicTech fair and square !

  • @vertikalniserklaz8694
    @vertikalniserklaz8694 4 дні тому

    Milan, Is there any video discussing how to implement communication between bounded contexts?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 дні тому

      Talked about sync communication here: ua-cam.com/video/hY342iy2PO0/v-deo.html

  • @LucasSantos-yw4nh
    @LucasSantos-yw4nh Рік тому +1

    Hi Milan,
    What would you say that are the main differences between Clean Architecture and Onion Architecture. Both look very similar to me. Is Onion Architecture a type of Clean Architecture?
    Congrats about the video, you are helping me a lot in Brazil.

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Hi Lucas, I'm glad you found the video useful!
      To me, they're pretty much the same thing. I just preferred the CA as a better name :)

  • @amarul92
    @amarul92 Рік тому +1

    Where do you put the connectionstrings for ef core and how do you wire it up in Program.cs or StartUp.cs. From what I gather, The Web project will have to reference EF Core?. Somewhere you put builder.Services.AddDbContext(connectionString); Is this in Web or infrastructure as an extension method?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      In the Web -> appsettings.json

    • @amarul92
      @amarul92 Рік тому

      @@MilanJovanovicTech Thanks for reply. In Web did you take a dependency on entity framework nuget?

  • @alexanderm8169
    @alexanderm8169 Рік тому +2

    When creating the UI/UX do you just implement the API endpoints from the Presentation layer to the UI/UX project?

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      Yes, usually I have a SPA consuming my API

    • @alexanderm8169
      @alexanderm8169 Рік тому

      Thanks for your reply, very much appreciated.
      Does this mean that the API is in another solution/class library?
      I thought the API should be nested in the presentation layer together with the SPA SomeProject.PresentationLayer
      -API (web api)
      -SPA (react.js)

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому

      @@alexanderm8169 The API is one project (solution) hosted in one repository.
      The SPA is a separate application hosted in a different repository.

  • @Kumar-oz5wr
    @Kumar-oz5wr Рік тому +1

    Nice video.
    Can you please create a video on onion architecture.

  • @microtech2448
    @microtech2448 10 місяців тому +1

    Hey Milan, Presentation layer sounds like the it should be web or api layer which user would be accessing directly. So what's the difference between Presentation and Web projects in your system? May be I am missing something.

    • @MilanJovanovicTech
      @MilanJovanovicTech  10 місяців тому

      Just an idea to isolate your API endpoints if you want to. Otherwise it's not really necessary.

    • @microtech2448
      @microtech2448 10 місяців тому

      @@MilanJovanovicTech Great 👍

  • @mohammadmz1058
    @mohammadmz1058 Рік тому +1

    Thanks for the video
    Personally I would not use this pattern on any project, since I find it to complicated, it introduces a significant overhead and it's just verbose.
    The benefit compared to a more simple project structure is small. But thanks for the video anyways👍

  • @rafaelpereiradias2567
    @rafaelpereiradias2567 10 місяців тому +1

    Milan, do you have any good book to learn OOP with c#?

  • @hororian
    @hororian Рік тому +1

    Do you have any idea on how to solve Presentation Web relation with gRPC ? gRPC requires base class generation for services while the controllers are just a simple classes with annotations.
    IMO, Web project is redundant because you can have multiple different presentation forms, instead I would suggest to work on developer discipline. :)

    • @MilanJovanovicTech
      @MilanJovanovicTech  Рік тому +1

      Going to have to research gRPC a little and get back to you, Miloš. I haven't really used it at all in practice, to be honest 🤷‍♂️