Fix Your Controllers By Refactoring To Minimal APIs

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 มิ.ย. 2024
  • Get the source code for this video for FREE → the-dotnet-weekly.ck.page/con...
    ☄️ 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
    Minimal APIs were added in .NET 6 and keep improving with each new version. Minimal APIs are easy to work with, more lightweight than controllers, and perform better. But how do you move from Controllers to Minimal APIs? That's what I will show you in today's video.
    Join my weekly .NET newsletter:
    www.milanjovanovic.tech
    Read my Blog here:
    www.milanjovanovic.tech/blog
    Chapters
    0:00 Controllers are dinosaurs
    1:31 Going from Controllers to Minimal APIs
    4:27 Using static methods for endpoints
    9:19 How to use Groups to manage endpoints
    10:35 Exposing endpoints on the API level
    12:30 Strong typing for Minimal APIs
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    Get the source code for this video for FREE → the-dotnet-weekly.ck.page/controllers-minimalapis

  • @vivekkaushik9508
    @vivekkaushik9508 9 หลายเดือนก่อน +15

    I love your videos Milan. I eagerly wait for your videos every week. I like your content style and the depth with which you explain like a teacher I never had. I wish you all the success, health and happiness. Never stop making these videos man. 😊❤

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

      Thank you so much, Vivek! You made my day :)

  • @gusflopes
    @gusflopes 9 หลายเดือนก่อน +28

    I didn't get why should I use this instead of controllers. Doesn't make sense in my head using this if I'm making a CRUD.

    • @JollyGiant19
      @JollyGiant19 9 หลายเดือนก่อน +7

      It just seems to be performance since it cuts out a lot of the background work the framework does for MVC. If you’re not doing MVC and simply returning JSON from some REST API, minimal APIs are tailored to that versus a controller doing the same.
      I don’t know what the actual gains are, that would be interesting to see!

    • @RafiXWPT
      @RafiXWPT 9 หลายเดือนก่อน +8

      I totally agree. I prefer and will stay with controller design. Performance boost from using minimal api is not worth it. For me code is much more clear and readable with controller approach

    • @zikkrype
      @zikkrype 9 หลายเดือนก่อน +5

      Agree. Also I have feeling that this minimal stuff would put a knife in your back when you need to do some specific stuff

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

      If controllers work for you, that's awesome. Why would you want to change that?
      I'm not against controllers in general. But they are easy to do wrong.
      I've seen so many examples of controllers with 50-100+ dependencies, and hundreds of endpoints.
      If you team can maintain thin controllers, more power to you.
      But when watching a video try to think from a different perspective.
      Not all developers have the same skill level as you, and they may not know how to write maintainable code.
      Minimal APIs are more compact, and at any point you're working with a single endpoint. So there is less room for error.

    • @microtech2448
      @microtech2448 9 หลายเดือนก่อน +1

      We start learning something, that time that seems shining and commonly used across the community. After some time that becomes obsolete and another thing starts shining and being talked about everywhere, we are caught in a trap of never ending process 😂

  • @hamitkarahan2973
    @hamitkarahan2973 9 หลายเดือนก่อน +2

    Very nice video, extremely simple explaining. I love your contents. Go on Milan! 💯

  • @cyrildouglas9262
    @cyrildouglas9262 9 หลายเดือนก่อน +2

    Thank you very much for the video, really glad that your channel is growing, you came a long way, you deserve more.

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

      Thanks a lot, I have some amazing things planned for the coming months 😁

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

      @@MilanJovanovicTech glad to hear that, looking forward to see more amazing stuff from you.

  • @AndreasFroyland
    @AndreasFroyland 8 หลายเดือนก่อน +2

    Thank you so much for taking your time to create such a great explaination. Cheers, buddy!

  • @thomascv321
    @thomascv321 9 หลายเดือนก่อน +7

    Awesome video Milan. I do agree with not unit testing your controllers. But we should write integration/functional tests, especially on customer facing API's. Good weekend!

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

      Thanks a lot, Thomas. We're on the same page with testing 👌

  • @MohammedHassan-ug4cu
    @MohammedHassan-ug4cu 9 หลายเดือนก่อน +1

    Awesome video Milan, you teaching style is great, Keep posting such content and do not stop....😍

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

    Thanks, Milan, This is useful and it's exactly what I was looking for.

  • @daniel49245
    @daniel49245 9 หลายเดือนก่อน +1

    Great straightforward aproach in this video. Keep up the good work. Liked, subbed for all.

  • @mhmrezaramezani4777
    @mhmrezaramezani4777 6 หลายเดือนก่อน +1

    Thanks alot. straightforward and useful video. ✌️

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

    Very interesting video. Thank you Milan!

  • @Tamer_Ali
    @Tamer_Ali 9 หลายเดือนก่อน +1

    Thanks a lot Milan, you are awesome. keep going 👍

  • @AndrewTateII
    @AndrewTateII 9 หลายเดือนก่อน +1

    Thanks, Milan, This is what I'm looking for.

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

      When did Andrew Tate start coding? 😁

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

      @@MilanJovanovicTech i just sold my bugatti 😂😂

  • @saulomarcosdev3849
    @saulomarcosdev3849 9 หลายเดือนก่อน +1

    Thank you Milan!

  • @10Totti
    @10Totti 8 หลายเดือนก่อน +2

    Great Tutorial!

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

      Thanks a lot, glad you liked it :)

  • @newtondantas
    @newtondantas 9 หลายเดือนก่อน +1

    This is awesome! Thanks!

  • @Rynardts
    @Rynardts 8 หลายเดือนก่อน +1

    Good stuff! Thanks!

  • @aluriramakrishna
    @aluriramakrishna 9 หลายเดือนก่อน +1

    Yes this is a really valuable one

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

    Very clear !

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

    That's a great video about the minimal api

  • @neotv15
    @neotv15 8 หลายเดือนก่อน +1

    Excelente video

  • @muhammedalikhan7559
    @muhammedalikhan7559 9 หลายเดือนก่อน +1

    You are amazing!!!!!

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

    Thank you sir for this valuable information... and all for free!

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

    bless you.

  • @ologungbaradavid2181
    @ologungbaradavid2181 9 หลายเดือนก่อน +1

    @milanJovanovicTech . Great video
    I guess its a case of different strokes for different folks....folks in this case are projects.
    Minimal API is a tool in the toolbox, you might use or not.
    on to the next one

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

    very nice

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

    Excellent video!
    Would you still use Mediatr with minimal endpoints? Seems you can just inject the class you need and call that. You won't need to deal with many dependencies not relevant to the specific endpoint, like we need in controllers case.

    • @pilotboba
      @pilotboba 9 หลายเดือนก่อน +3

      Mediatr has the advantage of a pipeline with behaviors. But sure, if all you are doing is calling a handle method of a class and passing the command, mediatr isn't really needed.

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

      MediatR has many more features than just passing commands/queries, which I find useful. So that's why I'm using it so extensively.

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

      @@MilanJovanovicTech Are there any videos available or planned in future regarding the many uses of MediatR other than command/query handling?

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

    That was really good - have you done security on Minimal API's

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

      Haven't released anything yet, have some projects in the pipeline

  • @user-rs1fh6gi1e
    @user-rs1fh6gi1e 9 หลายเดือนก่อน +1

    Thank you for the great video!
    The only thing, I didn't get point of using carter. First of all, anyway I have to not forget to mark my class with ICarterModule, then it's bring unclear behaviour to the class, because for me it's not obvious, that AddRoutes internally would register my endpoints class, and the last but not least, it's external dependency. Maybe I missed something?

  • @yunietpiloto4425
    @yunietpiloto4425 9 หลายเดือนก่อน +8

    Good video but I don’t think controllers need to be “fixed”. There’s nothing wrong with using controllers, it’s just another option on how you build an API. The title seems a little misleading to me, it would more accurate to title it something like “Converting you MVC API controller to minimal APIs” imo

  • @microtech2448
    @microtech2448 9 หลายเดือนก่อน +1

    We start learning something, that time that seems shining and commonly used across the community. After some time that becomes obsolete and another thing starts shining and being talked about everywhere, we are caught in a trap of never ending process 😂

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

      There are use cases for both. Experience with one or the other also plays a role. I'm not saying you replace all your controllers with Minimal APIs. But if you're starting a new project, at least give it a thought.

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

      Yeah, I would try that. And I like your contents. You are just bringing what is floating in the community and you are demonstrating them quite well.

  • @dannym817
    @dannym817 7 หลายเดือนก่อน +1

    Would love to see a minimal API example that handle login and register endpoints in DDD environment that uses an AuthorizationService.

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

      Have some samples:
      - th-cam.com/video/xBuLWaDcvu0/w-d-xo.html
      - th-cam.com/video/4cFhYUK8wnc/w-d-xo.html

  • @Add0w
    @Add0w 8 หลายเดือนก่อน +1

    Subscribed because I liked this video very much and willing to learn the minimal api, but do you know someone using it in production?

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

      Well, I used it in production. But that's a sample size of 1 :)

  • @morganishere123
    @morganishere123 9 หลายเดือนก่อน +2

    Awesome video, I didn't realise that using the Results inferface is almost like a discriminated union, very nice. What do you think about using carter to separate each endpoint into a separate class, like the handler command/handler approach used with MediatR, or is this overkill? Interested to get your opinion.

    • @kis.stupid
      @kis.stupid 9 หลายเดือนก่อน +1

      Seems a bit overkill indeed since these endpoints shouldn't hold the business logic. Rather orchestrate.
      The options shown in this video are pretty good, the vertical or maybe even modular approach. If you'd want to keep your business logic independent from AspNetCore framework, you could split those projects into one for the business logic and one for the minimal API.

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

      I don't think it's overkill. It's something I did in the VSA video.

  • @vikkymukesh4763
    @vikkymukesh4763 9 หลายเดือนก่อน +1

    Hi Milan,
    If we implemented the minimal api with the help of ICarter, we are able to call our endpoint. In such scenarios, I am going to implement the api versioning, how to pass the VersionSet value into the endpoint.

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

      Here are a bunch of examples for API versioning, and some of them are related to Minimal APIs: github.com/dotnet/aspnet-api-versioning/tree/3857a332057d970ad11bac0edfdbff8a559a215d/examples/AspNetCore/WebApi

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

    Interesting. I'll need to try this out. One question though: you did not mention (custom) attribues. How do they convert to minimal api if they're on controller or method level? Thanks.

    • @anilkarasahh
      @anilkarasahh 9 หลายเดือนก่อน +2

      I was looking for an answer to this question as well. I'm parking here :D

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

      ​@@anilkarasahh If you _have_ to use Attributes and cannot use "Endpoint filters" which are must much powerful (google them if you are interested, I have terrible experiences with trying to post links on TH-cam; No feedback and my comments just gets deleted after like 10 seconds), then you can simply add them to the Lambda itself:
      app.MapGet("/HelloWorld", [MyCustomAttributeThatReallyShouldBeAnEndpointFilter] (HttpContext httpContext) => {...logic here};

    • @m5s10
      @m5s10 9 หลายเดือนก่อน +2

      @@anilkarasahh It's a free parking zone my man :)

    • @user-xm7sh3vw8o
      @user-xm7sh3vw8o 9 หลายเดือนก่อน

      添加终结点筛选器

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

      You place attributes on the request delegate. Additionally, you can add them as metadata: github.com/Treblle/treblle-net-core/blob/master/TreblleCore/RouteHandlerBuilderExtensions.cs

  • @brigaderog177
    @brigaderog177 9 หลายเดือนก่อน +1

    thank you very much, i'll be using minimal apis from now on for my API routes

  • @theprimecoder4981
    @theprimecoder4981 3 หลายเดือนก่อน +2

    What if I use mediatr and only use mediatr as a service in my controllers, and the actual implementation is outside the presentation layer?

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

      So just use it to send commands/queries?

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

      @@MilanJovanovicTech Isn't that what Ardalis (Steve Smith) is doing with the REPR pattern?

  • @way_no6810
    @way_no6810 9 หลายเดือนก่อน +1

    Sweet......🤗

  • @onedev7316
    @onedev7316 9 หลายเดือนก่อน +1

    Excellentoooooo

  • @Chris-zb5nm
    @Chris-zb5nm 4 หลายเดือนก่อน

    Actually, the dotnet team didn't create the Minimal API to tell us we must switch from controllers to minimal api.
    Minimal API is just a simple way for testing and making a very small project faster without needing to create controllers and so on.
    It's just bunch of extensions methods that are using the same features that have been already existed before.
    It was also a copy of minimal apis from NodeJs and other languages & frameworks. People wanted to make a small API project very fast and easy with just a few lines of codes, so the Dotnet team added the extension methods to achieve this.

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

      "It's just bunch of extensions methods that are using the same features that have been already existed before." - I don't think it's that simple under the hood

  • @ademarvale3502
    @ademarvale3502 9 หลายเดือนก่อน +1

    How would you use an custom AuthorizationAttribute in minimal API's?

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

      You can create an attribute, and add it as metadata: github.com/Treblle/treblle-net-core/blob/master/TreblleCore/RouteHandlerBuilderExtensions.cs

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

      @@MilanJovanovicTech Thank you! Keep on the good work :)

  • @horacewillie3209
    @horacewillie3209 9 หลายเดือนก่อน +3

    What is really the advantage of going to route? The code looks way complex that the normal controller endpoint.

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

      How is it more complex?

    • @vincentjacquet2927
      @vincentjacquet2927 9 หลายเดือนก่อน +2

      @@MilanJovanovicTech Nice content. I won't say it is more complex I but do not find it simpler either. You do basically the same thing using an approach we are not used to.
      You started with MapControllers and a class inheriting from Controller that has the route definitions and methods to process HTTP requests by returning IActionResult.
      You end up with MapCarter and a class implementing a ICarterModule that has the route definition and methods to process HTTP requests by returning IResult.
      The shape of the code is the same (and you introduced a dependency to a third party library).

  • @Barghouthi
    @Barghouthi 9 หลายเดือนก่อน +1

    What is the name of the theme u use for your ide?

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

      R# dark theme (ReSharper)

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

      @@MilanJovanovicTech Been Looking for a while, Thanks !

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

    This is very good, but how do I define FromRoute, FromQuery, FromBody using this?

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

      You can use the attributes in the Minimal API request delegate ([FromQuery] MyQueryDto dto1, [FromBody] MyBodyDto dto2) => {}

  • @fahmiirfan6923
    @fahmiirfan6923 9 หลายเดือนก่อน +1

    I don't really like the group method, better left it full route, so when you found errornin the logs, you can debug by copypaste the URL to find your entry point controller

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

      Do you specify the entire route with controllers?

    • @fahmiirfan6923
      @fahmiirfan6923 9 หลายเดือนก่อน +1

      @@MilanJovanovicTech yes, like `/api/v1/schools/{id}/classes/{class_id}/students/{student_id}`
      It's more verbose but it's easier to debug. You can log that route spec, and then when debugging you can just copy paste that route to find your controller

  • @mad_t
    @mad_t 8 หลายเดือนก่อน +1

    According to MS docs Minimal API doesn't have model binding and validation, doesn't support view rendering
    So you can not replace ANY controller you want with minimal API.

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

      This is for APIs (it's in the name)

  • @xskyaflake
    @xskyaflake 9 หลายเดือนก่อน +2

    Good video, but which problem did you actually solve?

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

      Refactoring from controllers to Minimal APIs

    • @jessegador
      @jessegador 9 หลายเดือนก่อน +1

      @xskyaflake it's not solving anything, rather, finding problem to a solution.

  • @user-mm2no5kq2t
    @user-mm2no5kq2t 3 หลายเดือนก่อน

    The title promises "better performance," and it must be (for the sake of Milan's authority) evident somewhere between the lines and words in the content.

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

      All else being equal, Minimal APIs have more throughput (= better performance)

  • @90vackoo
    @90vackoo 9 หลายเดือนก่อน +2

    Awesome content Milan as always,
    I have been a silent content consumer of your channel and it just pains me to see weird criticism from people who don't appreciate the quality of content
    just wanted to ask how this would work with swagger configuration like producesresponsetype etc will it get a bit clunky?

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

      There's a method which you can call: ProducesResponseType
      So instead of an attribute, you call a method.

  • @pavelromashuk237
    @pavelromashuk237 9 หลายเดือนก่อน +1

    Does anyone measure the performance of controllers and minimal APIs, what is the difference?

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

      I'll make a video about it!

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

      @@MilanJovanovicTech Cool. Looking forward!

  • @johncerpa3782
    @johncerpa3782 9 หลายเดือนก่อน +1

    what were you scared of in the thumbnail? :p , good vid

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

      The people defending controllers in the comments 😂

  • @kis.stupid
    @kis.stupid 9 หลายเดือนก่อน +1

    Good stuff! I need to learn your presentation style, so to the point. What does the CarterModule internally do? Grabbing all those IEndpointBuilder usages?

    • @pilotboba
      @pilotboba 9 หลายเดือนก่อน +1

      Yea, basically. It's open source so you can view the code.

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

      Maybe I'll implement a Carter clone in a future video to show how simple the concept is.

  • @livehole3635
    @livehole3635 7 หลายเดือนก่อน +1

    I like controller base api

  • @sokoo1978
    @sokoo1978 9 หลายเดือนก่อน +1

    How much faster is this? Looks pretty unpolished and complicated compared to the controllers.

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

      Depends on your workload and what you are doing, but it can offer a noticeable improvement in throughput. I'll do video discussing performance with benchmarks.
      The memory allocation of Minimal APIs is also reduced.

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

      @@MilanJovanovicTech Awesome, I love to see video to compare the performance and memory allocation compare between controllers and minimal APIs.

  • @Th3MoL3
    @Th3MoL3 9 หลายเดือนก่อน +1

    I can't stop laughing at the thumbnail 🤣

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

      A real work of art. I'm pretty happy with how it turned out 😉

  • @MorethnaEdits
    @MorethnaEdits 9 หลายเดือนก่อน +1

    Thanks for that one, I'll refactor my controllers asap 😅

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

      Oh god, now your boss will be calling me 😂

  • @vasiliylu8054
    @vasiliylu8054 9 หลายเดือนก่อน +3

    Why? This looks like an invention of controller in perspective with increasing of complexity. Keep it minimal.

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

      How does it increase complexity?

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

      I didn't express my thought quite correctly(English isn’t very well). As the complexity of the project increases, the code using the minimal api will become more and more similar to the code using controllers, I think.

  • @EdKolis
    @EdKolis 9 หลายเดือนก่อน +1

    I tried this but my JoyCons still won't reattach to my Switch 😛

  • @techpc5453
    @techpc5453 8 หลายเดือนก่อน +1

  • @Kingside88
    @Kingside88 9 หลายเดือนก่อน +2

    Thank you. I did'nt know about grouping minimal Apis and the strong typed result.
    However, I do not like Carter because it's a dependency to be lazy as developer.
    I mean you would know very soon, when you forget to register a group of minimal apis.

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

      Carter helps so that you don't have to remember - it just works 😁

  • @EugeneZavalko
    @EugeneZavalko 9 หลายเดือนก่อน +2

    Indeed this is really useful video on how to refactor old API. Can you make a video on how to use Auth with minimal API?

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

      Will do!

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

      @@MilanJovanovicTech Thanks a lot. It would be interesting with roles.

  • @softcodeacademy
    @softcodeacademy 9 หลายเดือนก่อน +1

    Minimal APIs when grows larger in size start to look like controller. Keep it minimal.

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

      Endpoints should be minimal regardless.

  • @zikkrype
    @zikkrype 9 หลายเดือนก่อน +1

    Nice video mate. Still I don’t like this minimal api. I find it so damn annoying

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

      That's fine, we have options in .NET and we can decide what works for our projects 😁

  • @khalilovk
    @khalilovk 9 หลายเดือนก่อน +9

    1.why would you even need to POLUTE your project with this carter library? it takes a misery amount of code to implement the same yourself.
    2.controllers are still better for documenting your APIs. Powerful attributes like [SwaggerResponse] and comments are still more convenient to use in controllers. And this is crucial for any serious project with documented apis.

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

      1. Why would I reinvent the wheel? Plus it has some pre-post request middleware that can be useful.
      2. You can use them just the same with Minimal APIs - except you need to call methods for each endpoint

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

      Minimal APIs have all the same Swagger support but with method calls rather than attributes. But so far I haven't seen any missing from Controller based api documentation.

    • @jessegador
      @jessegador 9 หลายเดือนก่อน +1

      @khalilovk they are finding problem to a solution. Lol

  • @kiran-Joy
    @kiran-Joy 8 หลายเดือนก่อน +1

    If your controller is growing exponentially then that itself is a design problem and not an issue with controllers. If you put your order , Catalog , invoice APIs in one controller surely that controller has a lot of code that is not needed for all APIs but that is just poor design choice

  • @yuGesreveR
    @yuGesreveR 7 หลายเดือนก่อน +2

    The video in short:
    Controllers are bad and wasteful. But we can do functionally the same with minimal API (although we could do exectly the same stuff with parameter injection and so on with controllers). However, to use it we have to implement an ammount of custom methods or use some third-party library. But now we do not use controllers.
    Why?
    I don't get the point. Really. With a wise approach you can use controllers without memory loss or injecting unnecessary stuff. Moreover, it is more convenient to auto-generate swagger by controller xml-docs (rather than do tricks with MinAPI). Basically, what I want to say is that the claim that MinAPI is definitely better than controllers is false

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

      What about cohesion? Minimal APIs make it easy to implement REPR

    • @yuGesreveR
      @yuGesreveR 7 หลายเดือนก่อน +2

      @@MilanJovanovicTech no one prevents you from structuring controllers as you want. They are effectively just routing groups. So if you see that your controller consists of actions that should not be together, then just split it. A controller can even consists of a singular action. That is fine. But you can also describe "sibling" methods, that, for example, use same set of services (like, loggers or db contexts) and describe them in a single class. That also prevents you from duplicating same injections (you can move them to the constructor), but doesn't prevent you in any way to specify services unique for a certain action (and inject it via FromServicesAttribute).
      Once again. I do not say that MinAPI is evil or controllers are the best and everyone should use them. But I just want to be honest and mention that it all depends. Depends on your cases. Depends on complexity of your domain. What I saw in this video was mostly about "how we can implement same structure as for controllers, but without controllers". I didn't see (particularly in this scenario) the reason why we should do it. We changed nothing here, except now our logic is static and we can call it from everywhere else. But again there is not a reason for that. At least I don't see it (maybe I'm wrong).

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

    I just dont like this, idk why minimal and static api's like harding code. Is any performance testing on there?

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

      Here's a benchmark from FastEndpoints: fast-endpoints.com/benchmarks#head-to-head-benchmark
      You can see Minimal APIs are ~40%ish faster than controllers

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

      Thank you milan!@@MilanJovanovicTech

  • @magashkinson
    @magashkinson 9 หลายเดือนก่อน +8

    Controllers are better. With controllers it is easy to register endpoints using built in method without external libraries. It makes convenient dependency injection because we can inject them just one time in controller instead of injecting them multiple times in each endpoint.
    And also returning results using methods like Ok, NotFound looks much shorter and readable than TypedResults.Ok etc. I do not need to call any static class to return result in controller method

    • @pilotboba
      @pilotboba 9 หลายเดือนก่อน +5

      You are not really injecting them multiple times. Yes, you are coding it in each endpoint rather than in the controller class constructor. If you do feature slicing and put the endpoint in a feature file your code can be organized differently. You don't need the overhead of a controller.
      If you don't want to use TypedResults, you don't have to, stick to IResult.
      To each their own of course. If you prefer controllers, that's great. They aren't going anywhere.
      Your comment to say they are "better" is purely subjective.
      Objectively, however, minimal API endpoints are faster.

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

      what exacly do you mean be saying "minimal endpoints are faster"?, do you mean that they are faster to write or that the responses from such endpoints are faster?@@pilotboba

    • @victor1882
      @victor1882 9 หลายเดือนก่อน +1

      Also, you don't need Carter to register the endpoints, I, for one, prefer the explicitness of defining the endpoints and mapping them, with full code navigation and references, no implicit reference

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

      @@bobek8030 Yes, I mean they are more performant during runtime.

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

      @@pilotbobamy subjective opinion is BETTER

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

    I think minimal APIs lack in ways to make good API documentation. Now you need to work with an array of arguments and modify their properties instead of adding XML comments, status code descriptions using attributes, and so on.

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

      That's true, a possible disadvantage

  • @rogerstich7603
    @rogerstich7603 2 หลายเดือนก่อน +1

    Hm you just converted a Controller into a Minimal API which uses more Boilerplate than before and has no benefit at all. Im sorry but you stated at the beginning "For more cohesion and performance" but you doesnt show it. The only difference is the Method Injection instead of Constructor but thats i can do in an old fashioned Controller aswell. Based on your example here i see no reason why i should switch to Minimal APIs. There might be benefits but it would be helpfull if you really point them out.

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

      When you encounter controller with 20+ endpoints, and some of them have anything than the simplest logic inside, it starts making a lot of sense. You can easily have one endpoint per file, with complete request/response classes. Your whole feature in one place. Albeit, not many people still appreciate this aspect, nor do they enjoy moving away from controllers. I talked about it briefly here: www.milanjovanovic.tech/blog/vertical-slice-architecture

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

      @@MilanJovanovicTechThank you for your answer. I can agree with you to some extend. I just want to point out that moving to minimal api is not the only solution to this. For example if i have more than 20 endpoints in one file i would first ask the question if they really belong together or if there better ways to structure the api and i would ask this regardless the api approach. Another way to solve this would be to use partial classes. Anyway the main topic i really learn from this video was how to structure minimal apis. This was a thing i wasnt sure about how to handle it at all.

  • @S3Kglitches
    @S3Kglitches 9 หลายเดือนก่อน +1

    sorry no

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

      Why?

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

      @@MilanJovanovicTech for large real world apps it's unusable and unmaintainable

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

      @@S3Kglitches If anything it's easier - because the dependencies for each endpoint are clear.
      In a controller, all dependencies are shared between endpoints.

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

    Seriously? Converting Controllers to minimal APIs? You are finding problems with a solution.

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

      Someone out there will want to migrate from controllers to Minimal APIs

    • @krccmsitp2884
      @krccmsitp2884 9 หลายเดือนก่อน +1

      It's an alternative, not a replacement. It makes more sense when you don't have simple MVC-style CRUD-based apps due to its flexibility.

  • @iliyandimitrov5539
    @iliyandimitrov5539 14 วันที่ผ่านมา

    Many of the points you are doing in the begging are not valid. You should not put all of your logic in a single controller. If you have services that are not used or used by few methods then pull them out in a separate controller class.

    • @MilanJovanovicTech
      @MilanJovanovicTech  13 วันที่ผ่านมา

      Those are fair points that make sense. In practice, I've rarely (if ever) seen that done.

  • @allannielsen4752
    @allannielsen4752 9 หลายเดือนก่อน +3

    Thanks for the journey, you've come a long way, and I have enjoyed your content, but I just can't respect a creator that needs stupid thumbnails and click bait headings. this is a trend that might gain views in the short term, but do you really want views from people with no self control or gain a following that comes back again and again for the content? I'm sorry, unsubscribed.

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

      I'm sorry you feel that way. I wish you a heartfelt goodbye. Stay awesome!

    • @sneer0101
      @sneer0101 9 หลายเดือนก่อน +2

      What a bizarre comment. Grow up dude.

    • @wmalgoire
      @wmalgoire 9 หลายเดือนก่อน +1

      Sorry but I have to jump in. I agree 100% with your opinions on click bait titles, annoying likes and subscribe "in your face" pop-ins.
      But first I'd be curious to understand what makes you think this video has a click bait title 😳..
      But most important, you're missing the only thing that matters.. Is the content valuable? Did you learn something? Do you think the author worked hard to share quality content or just did a copy/paste of a previous tutorial ?
      I feel sorry for you, everyone has his opinion and we are all free to disagree with Milan's opinions.. but he deserves at least respect and he is definitely not a click baiter ! I wish I could produce half what he's bringing to the community.
      That being said, keep up the good work Milan. This video was awesome for me, and just in time, as I currently need to find quick and actionable tips to get away from controllers 👍🙏
      Just ignore the haters and lousy voices. Inevitable sadly, whoever you are and you do. I'm pretty sure Gandhi, Dr Martin Luther King, Nelson Mandela,.. and all the great people who fought as a force of good would get their share of haters in social media. But I disgress 😂
      Stay awesome, and thank you

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

      @@wmalgoire Not speaking for the OP, but maybe because of the word "Fix". There's nothing "broken" about controllers.

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

      Apologies if that came across as a "hater", that was not my intent, hence the thanks. And yes Milan's content is usually of a high standard, and I agree does deserve all his subscribers. I am finding most social media platforms these days toxic and have been leaving most of late.
      I wish you all the best, particularly Milan, and hope you all thrive with the content presented.