The Simplest Vertical Slice Architecture With .NET 8

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2024

ความคิดเห็น • 94

  • @MilanJovanovicTech
    @MilanJovanovicTech  4 หลายเดือนก่อน +3

    Get the source code for this video for FREE → the-dotnet-weekly.ck.page/vsa-structure
    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

    • @TheOmokage
      @TheOmokage 3 หลายเดือนก่อน +1

      How to combine microservices with slices?

  • @cas818028
    @cas818028 4 หลายเดือนก่อน +4

    Something else that nobody has mentioned, it’s super easy to
    Wrap the entire slice in a feature flag. Which opens door for a ton of flexible development options.

  • @olivier0003
    @olivier0003 4 หลายเดือนก่อน +6

    Hi Milan, you produce so many interesting videos, that it takes all my day to view all of them !

  • @jawadsrour8490
    @jawadsrour8490 4 หลายเดือนก่อน

    Great video!
    A nice video you could do:
    - best practices C#12
    - Best practices .NET 8 (top X best practices in general)…
    - Doing some talks on clean code…

  • @nikolaknezevic2117
    @nikolaknezevic2117 4 หลายเดือนก่อน +2

    Great video! I hope you consider creating a full video on sharing code between slices. Code duplication can be a challenging, it would be nice to see different strategies for reducing duplication.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +2

      Yes, that's something I want to tackle

  • @Fikusiklol
    @Fikusiklol 4 หลายเดือนก่อน

    Great stuff, Milan and also much congratz on getting MVP :)
    As for the video, I, personally, prefer using Clean + Vertical at the same time for non-crud apps, separating slices (folders basically) between projects. I.e "Products" folder in all projects. With enough dedication and discipline you can get best of both worlds.
    Great example anyway and love your approach with IEndpoint reflection stuff :)

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      Thank you!
      I'm doing something similar to what you are when using CA. Works great.

  • @MohamedibinAhmed
    @MohamedibinAhmed 2 หลายเดือนก่อน

    Thank you Milan for the easiest explanation... Can i use controller instead of map endpoint?

  • @ruekkart
    @ruekkart 4 หลายเดือนก่อน +1

    Nice, finally I can see a good and complete VSA example!
    Just one question, how would you suggest using this for gRPC, given that you need to handle proto files?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +2

      That's a technical concern. Maybe I should do a VSA + gRPC video?

    • @ruekkart
      @ruekkart 4 หลายเดือนก่อน

      @@MilanJovanovicTech that'd be awesome, please 😃

  • @buri-kizilkaya
    @buri-kizilkaya 4 หลายเดือนก่อน +1

    Thank you for your videos. I like the vertical slice architecture. What do you think about organising vertical slice architecture with multiple "mains" like a WebAPI project and a console project. The core should be the same on both. How do you structure such a project? My answer is to make the core vertical slice architecture and the multiple main project are implementend like the hexagonal architecture which access the public interface of the core.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      MediatR solves this pretty easily 😅

    • @buri-kizilkaya
      @buri-kizilkaya 4 หลายเดือนก่อน

      @@MilanJovanovicTech my question is how to structure such projects.

  • @drhdev
    @drhdev 4 หลายเดือนก่อน +4

    Could you do a video on Owned Properties vs EF's new Complex Types and the nuances between them?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +2

      I did: th-cam.com/video/LhCD5CUSP6g/w-d-xo.html

    • @drhdev
      @drhdev 4 หลายเดือนก่อน

      @@MilanJovanovicTechawesome thank you!

  • @MjwAllMusic
    @MjwAllMusic 4 หลายเดือนก่อน +1

    Could you make a video about the best practices with multithreading, async, etc?

  • @ChristophLoacker
    @ChristophLoacker 2 หลายเดือนก่อน

    great video! one question, if you have another vSlice and you access the same datamodel, do you share those objects? if so, how do you manage dependencies? if not, how do you deal with rich domain models?

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 หลายเดือนก่อน

      If sharing, use the data model from the slice where it makes most sense. Duplicating them also isn't too much of an issue, but it becomes difficult to maintain if they both need to change at the same time.

  • @IAmFeO2x
    @IAmFeO2x 4 หลายเดือนก่อน +1

    Interesting approach - but is this really feasible when things get more complicated? Would you organize a more complex project this way? I organize my vertical slices in a hierarchical folder structure - this scaled well for me so far.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +1

      Projects don't start out complicated (most of the time). They become complicated.
      So this is a great way to start any project, and restructure as your project grows.

    • @IAmFeO2x
      @IAmFeO2x 4 หลายเดือนก่อน

      @@MilanJovanovicTech OK, thanks for your response. I'd still recommend to start right with folders as no subsequent switch is required as the project grows.

  • @fritzjimenez9109
    @fritzjimenez9109 4 หลายเดือนก่อน

    pretty simple and straight forward 🤔👍

  • @kodindoyannick5328
    @kodindoyannick5328 4 หลายเดือนก่อน

    Wonderful video. Thanks much!

  • @sirg7573
    @sirg7573 หลายเดือนก่อน

    In the source code, I see that AppDbContext is under Products. So does this mean there will be a DbContext instance for each vertical slice? Shouldn't AppDbContext be moved out of Products?

    • @MilanJovanovicTech
      @MilanJovanovicTech  หลายเดือนก่อน

      Yes we can do that. But we also don't have to. I'd move it out of the slice most likely.

  • @alessandrohudson5221
    @alessandrohudson5221 4 หลายเดือนก่อน

    Hey Milan,
    Thank you for sharing this resource to us. However, a have a doubt: I have an entity named "Item" in selling and stock context, and if I understood well this entity can does move with cross-cutting. In this case, will are through of domain events? For example, I sold a guitar and I need to update my stock, can I create a domain event to update it?

    • @Ry4nWTF
      @Ry4nWTF 4 หลายเดือนก่อน

      to me this sounds super clean. instead of injecting a StockService or StockRepo, and all the other parts of the system that needs that info

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      Of course, this doesn't exclude using domain events or any other pattern

  • @arteqppp6223
    @arteqppp6223 4 หลายเดือนก่อน

    I'm really interested in how to structure entities and their configurations in vertical slice. Should I place these two in same folder as my request command handler and response classes? Or maybe place them in different folders?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      Place them next to the DbContext? VSA is more about organizing around business capabilities. EF Core configurations are a minor concern.

  • @YoelQuintanaCarrera
    @YoelQuintanaCarrera 4 หลายเดือนก่อน

    Excellent video as always!!!!.

  • @pacific_punch1
    @pacific_punch1 3 หลายเดือนก่อน

    vsa is great, love it

  • @ajdinhusic2574
    @ajdinhusic2574 4 หลายเดือนก่อน

    Hi Milan, thanks for the great video!
    I have a question though. Is there a purpose for putting the different components inside a static class (effectively the REPR pattern), as opposed to putting it in a namespace? And then reference it in the same way if you like, i.e. CreateProduct.Request, etc.. ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      Less verbose:
      - CreateProduct.Request/CreateProduct.Response
      - As opposed to CreateProductRequest/CreateProductResponse
      I can use simpler names within the vertical slice, where these types matter

    • @ajdinhusic2574
      @ajdinhusic2574 4 หลายเดือนก่อน

      @@MilanJovanovicTech I was thinking slightly different, calling the types still the same names, but in a folder, so:
      CreateProduct/
      - Request.cs
      - Response.cs
      etc.

    • @stefanmoller5953
      @stefanmoller5953 หลายเดือนก่อน

      The struggle of intelligence to find the correct request together with auto includes could easily mess up the development. Having the static class wrapper hides the matching types outside of the static classes scope

    • @stefanmoller5953
      @stefanmoller5953 หลายเดือนก่อน

      Intellisense...

  • @mehdi-vl5nn
    @mehdi-vl5nn 4 หลายเดือนก่อน

    I do have a hard time understanding what 'use case' implies here! Is 'use case' in the sense of requirements, as it exists in RUP? If yes, that would end up being a class diagram. However, it seems the meaning of 'use case' is different in the context of CA

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +1

      A use case represents a unique piece of functionality in the system.
      Copy-paste from Uncle Bob's article:
      ---
      Use Cases
      The software in this layer contains application specific business rules. It encapsulates and implements all of the use cases of the system. These use cases orchestrate the flow of data to and from the entities, and direct those entities to use their enterprise wide business rules to achieve the goals of the use case.
      We do not expect changes in this layer to affect the entities. We also do not expect this layer to be affected by changes to externalities such as the database, the UI, or any of the common frameworks. This layer is isolated from such concerns.
      We do, however, expect that changes to the operation of the application will affect the use-cases and therefore the software in this layer. If the details of a use-case change, then some code in this layer will certainly be affected.
      ---

  • @krccmsitp2884
    @krccmsitp2884 4 หลายเดือนก่อน

    I like your approach.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +1

      Thanks

    • @krccmsitp2884
      @krccmsitp2884 4 หลายเดือนก่อน

      @@MilanJovanovicTech do you combine DDD with Vertical Slices, eg subdomain = slice?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +1

      @@krccmsitp2884 Most likely, yes. I'll expand on this in future videos and we can discuss possible approaches.

    • @krccmsitp2884
      @krccmsitp2884 4 หลายเดือนก่อน

      @@MilanJovanovicTech great!

  • @davood7497
    @davood7497 4 หลายเดือนก่อน

    Good Job !

  • @Ziirf
    @Ziirf 4 หลายเดือนก่อน

    I like the idea of vertical slice architecture. I am just worried how it would work in a large repo.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      You can evolve it into anything more strict later

  • @Bennevisie
    @Bennevisie 4 หลายเดือนก่อน

    Hi Milan. This is great, but it can be even simpler. You don't need the repository layer (just use Dapper and DbUp).

    • @drhdev
      @drhdev 4 หลายเดือนก่อน +3

      Is the repository layer in the room with us right now?

    • @Ry4nWTF
      @Ry4nWTF 4 หลายเดือนก่อน +1

      @@drhdev years of overusing repo layers has fried this guys mind

    • @ppenxhchqlz3113
      @ppenxhchqlz3113 4 หลายเดือนก่อน

      @@drhdev HAHAHHAHAHHA

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      EF Core is simple enough for me

  • @timur2887
    @timur2887 4 หลายเดือนก่อน

    Great, thanks!

  • @ducaipham1248
    @ducaipham1248 4 หลายเดือนก่อน

    can you compare vertical slice with clean architecture?

  • @simonklein2335
    @simonklein2335 4 หลายเดือนก่อน

    Great Video like always :D You mentioned to map the validation result to a ProblemDetails and currently I am trying to that with the Results pattern. So map the Errors in a Result to a ProblemDetails, but I am failing misserably. Could you make a video on that, where you show, how to map the Errors of a Result to ProblemDetails within minimal API. I know it's fairly easy to that with MVC controllers, but MinimalAPI gives me a headache.
    My use case is that I am validating business logic and want to return custom errors. So for example CreateProducts validates if the product already exists and if it exists return Result.Fail("custom message with error details). And I want to map the Error to a problem details within minimalAPI. The controller would return something like this:
    return response.IsSucess ? Results.Ok() : Results.BadRequest(response.error)

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน +1

      I talked about it here: th-cam.com/video/YBK93gkGRj8/w-d-xo.html

  • @petropzqi
    @petropzqi 4 หลายเดือนก่อน

    Thank you so much

  • @HernanIannella
    @HernanIannella 4 หลายเดือนก่อน

    What visual studio theme is that?

  • @GordonKenaston
    @GordonKenaston 4 หลายเดือนก่อน

    I like it! 🎉

  • @joandimko3063
    @joandimko3063 หลายเดือนก่อน

    Anyone able to refactor fluent validation code into an external class, without the need to write it at every endpoint Handler method?

  • @lucifer-5ybtn
    @lucifer-5ybtn 4 หลายเดือนก่อน

    theme name??

  • @Tabgyn
    @Tabgyn 4 หลายเดือนก่อน

    Is it just me that swagger there are no operations defined in the spec using this approach?

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      Probably, Minimal APIs are a bit limited with Swagger

  • @Sharondevbd
    @Sharondevbd 4 หลายเดือนก่อน

    Brother Need some interview ques & ans to Crack .Net Jobs

  • @WangAndrew
    @WangAndrew 3 หลายเดือนก่อน

    What if we put all the code in the minimal/controller API method, it even omits the mediaR...🤣🤣🤣

  • @BlindVirtuoso
    @BlindVirtuoso 4 หลายเดือนก่อน

    Nice, but I didn't like the tip on refactoring out code duplication to a shared component. That's a premature abstraction and introduces unnecessary coupling between vertical slices. What I mean is that today's duplicate parts probably evolve in different directions in the future.

    • @MilanJovanovicTech
      @MilanJovanovicTech  4 หลายเดือนก่อน

      That's something to be decided by the developers