Fix Your Controllers By Refactoring To Minimal APIs

2024 ж. 16 Мам.
31 459 Рет қаралды

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

Пікірлер
  • Get the source code for this video for FREE → the-dotnet-weekly.ck.page/controllers-minimalapis

    @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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. 😊❤

    @vivekkaushik9508@vivekkaushik95088 ай бұрын
    • Thank you so much, Vivek! You made my day :)

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Very nice video, extremely simple explaining. I love your contents. Go on Milan! 💯

    @hamitkarahan2973@hamitkarahan29738 ай бұрын
    • Thank you so much 😀

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Thank you very much for the video, really glad that your channel is growing, you came a long way, you deserve more.

    @cyrildouglas9262@cyrildouglas92628 ай бұрын
    • Thanks a lot, I have some amazing things planned for the coming months 😁

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech glad to hear that, looking forward to see more amazing stuff from you.

      @cyrildouglas9262@cyrildouglas92628 ай бұрын
  • 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!

    @thomascv321@thomascv3218 ай бұрын
    • Thanks a lot, Thomas. We're on the same page with testing 👌

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • This is awesome! Thanks!

    @newtondantas@newtondantas8 ай бұрын
    • Glad you found it valuable! :)

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Great Tutorial!

    @10Totti@10Totti8 ай бұрын
    • Thanks a lot, glad you liked it :)

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Awesome video Milan, you teaching style is great, Keep posting such content and do not stop....😍

    @MohammedHassan-ug4cu@MohammedHassan-ug4cu8 ай бұрын
    • Thank you so much 😀

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Thank you Milan!

    @saulomarcosdev3849@saulomarcosdev38498 ай бұрын
    • You're welcome!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Thanks a lot Milan, you are awesome. keep going 👍

    @Tamer_Ali@Tamer_Ali8 ай бұрын
    • Thanks, will do! :)

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Thank you so much for taking your time to create such a great explaination. Cheers, buddy!

    @AndreasFroyland@AndreasFroyland7 ай бұрын
    • Glad it was helpful! My pleasure :)

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • Yes this is a really valuable one

    @aluriramakrishna@aluriramakrishna8 ай бұрын
    • Glad you found it valuable 💪

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Thanks, Milan, This is what I'm looking for.

    @AndrewTateII@AndrewTateII8 ай бұрын
    • When did Andrew Tate start coding? 😁

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech i just sold my bugatti 😂😂

      @AndrewTateII@AndrewTateII8 ай бұрын
  • Great straightforward aproach in this video. Keep up the good work. Liked, subbed for all.

    @daniel49245@daniel492458 ай бұрын
    • Thanks a lot, Daniel! :)

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Good stuff! Thanks!

    @Rynardts@Rynardts7 ай бұрын
    • Glad you liked it!

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • 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.

    @gusflopes@gusflopes8 ай бұрын
    • 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!

      @JollyGiant19@JollyGiant198 ай бұрын
    • 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

      @RafiXWPT@RafiXWPT8 ай бұрын
    • Agree. Also I have feeling that this minimal stuff would put a knife in your back when you need to do some specific stuff

      @zikkrype@zikkrype8 ай бұрын
    • 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.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • 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 😂

      @microtech2448@microtech24488 ай бұрын
  • You are amazing!!!!!

    @muhammedalikhan7559@muhammedalikhan75598 ай бұрын
    • Thanks a lot!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Thanks alot. straightforward and useful video. ✌️

    @mhmrezaramezani4777@mhmrezaramezani47776 ай бұрын
    • Awesome, glad you enjoyed it ;)

      @MilanJovanovicTech@MilanJovanovicTech6 ай бұрын
  • Thanks, Milan, This is useful and it's exactly what I was looking for.

    @alejandroaguirre7696@alejandroaguirre76964 ай бұрын
    • You're welcome!

      @MilanJovanovicTech@MilanJovanovicTech4 ай бұрын
  • Very interesting video. Thank you Milan!

    @kodindoyannick5328@kodindoyannick53283 ай бұрын
    • My pleasure!

      @MilanJovanovicTech@MilanJovanovicTech3 ай бұрын
  • 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.

    @yanivrubin7202@yanivrubin72028 ай бұрын
    • 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.

      @pilotboba@pilotboba8 ай бұрын
    • MediatR has many more features than just passing commands/queries, which I find useful. So that's why I'm using it so extensively.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech Are there any videos available or planned in future regarding the many uses of MediatR other than command/query handling?

      @Swzvtlbngfd@Swzvtlbngfd8 ай бұрын
  • Thank you sir for this valuable information... and all for free!

    @Joe1qz@Joe1qz7 ай бұрын
    • Most welcome!

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • 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.

    @m5s10@m5s108 ай бұрын
    • I was looking for an answer to this question as well. I'm parking here :D

      @anilkarasahh@anilkarasahh8 ай бұрын
    • ​@@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 KZhead; 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};

      @modernkennnern@modernkennnern8 ай бұрын
    • @@anilkarasahh It's a free parking zone my man :)

      @m5s10@m5s108 ай бұрын
    • 添加终结点筛选器

      @user-xm7sh3vw8o@user-xm7sh3vw8o8 ай бұрын
    • 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

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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?

    @user-rs1fh6gi1e@user-rs1fh6gi1e8 ай бұрын
    • How would you implement it?

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • bless you.

    @barnabassolomon1629@barnabassolomon16293 ай бұрын
    • Thanks!

      @MilanJovanovicTech@MilanJovanovicTech3 ай бұрын
  • @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

    @ologungbaradavid2181@ologungbaradavid21818 ай бұрын
    • I completely agree

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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.

    @morganishere123@morganishere1238 ай бұрын
    • 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.

      @kis.stupid@kis.stupid8 ай бұрын
    • I don't think it's overkill. It's something I did in the VSA video.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Excelente video

    @neotv15@neotv157 ай бұрын
    • Thanks!

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • 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.

    @vikkymukesh4763@vikkymukesh47638 ай бұрын
    • 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

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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 😂

    @microtech2448@microtech24488 ай бұрын
    • 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.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • 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.

      @microtech2448@microtech24488 ай бұрын
  • Subscribed because I liked this video very much and willing to learn the minimal api, but do you know someone using it in production?

    @Add0w@Add0w7 ай бұрын
    • Well, I used it in production. But that's a sample size of 1 :)

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • That's a great video about the minimal api

    @misonosenpai3168@misonosenpai316826 күн бұрын
    • Glad you liked it!

      @MilanJovanovicTech@MilanJovanovicTech25 күн бұрын
  • thank you very much, i'll be using minimal apis from now on for my API routes

    @brigaderog177@brigaderog1778 ай бұрын
    • Awesome!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Very clear !

    @rachidkacel3388@rachidkacel338823 күн бұрын
    • Ty!

      @MilanJovanovicTech@MilanJovanovicTech22 күн бұрын
  • Excellentoooooo

    @onedev7316@onedev73168 ай бұрын
    • Thank you sir!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • How would you use an custom AuthorizationAttribute in minimal API's?

    @ademarvale3502@ademarvale35028 ай бұрын
    • You can create an attribute, and add it as metadata: github.com/Treblle/treblle-net-core/blob/master/TreblleCore/RouteHandlerBuilderExtensions.cs

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech Thank you! Keep on the good work :)

      @ademarvale3502@ademarvale35028 ай бұрын
  • 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

    @yunietpiloto4425@yunietpiloto44258 ай бұрын
    • I need to balance between CTR and content 😅

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • You are 100% correct

      @manojweerasooriya7555@manojweerasooriya75555 ай бұрын
  • Good video, but which problem did you actually solve?

    @xskyaflake@xskyaflake8 ай бұрын
    • Refactoring from controllers to Minimal APIs

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @xskyaflake it's not solving anything, rather, finding problem to a solution.

      @jessegador@jessegador8 ай бұрын
  • Sweet......🤗

    @way_no6810@way_no68108 ай бұрын
    • Thanks!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • very nice

    @grimmersnee@grimmersnee5 ай бұрын
    • Thanks

      @MilanJovanovicTech@MilanJovanovicTech5 ай бұрын
  • Would love to see a minimal API example that handle login and register endpoints in DDD environment that uses an AuthorizationService.

    @dannym817@dannym8176 ай бұрын
    • Have some samples: - kzhead.info/sun/q6aufLuZe5WsqGg/bejne.html - kzhead.info/sun/Z8d_mL2NgmqtoZs/bejne.html

      @MilanJovanovicTech@MilanJovanovicTech6 ай бұрын
  • That was really good - have you done security on Minimal API's

    @CarrigansGuitarClub@CarrigansGuitarClub2 ай бұрын
    • Haven't released anything yet, have some projects in the pipeline

      @MilanJovanovicTech@MilanJovanovicTech2 ай бұрын
  • What is the name of the theme u use for your ide?

    @Barghouthi@Barghouthi8 ай бұрын
    • R# dark theme (ReSharper)

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech Been Looking for a while, Thanks !

      @Barghouthi@Barghouthi8 ай бұрын
  • What if I use mediatr and only use mediatr as a service in my controllers, and the actual implementation is outside the presentation layer?

    @theprimecoder4981@theprimecoder49812 ай бұрын
    • So just use it to send commands/queries?

      @MilanJovanovicTech@MilanJovanovicTech2 ай бұрын
    • @@MilanJovanovicTech Isn't that what Ardalis (Steve Smith) is doing with the REPR pattern?

      @jrandallsexton@jrandallsextonАй бұрын
  • What is really the advantage of going to route? The code looks way complex that the normal controller endpoint.

    @horacewillie3209@horacewillie32098 ай бұрын
    • How is it more complex?

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@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).

      @vincentjacquet2927@vincentjacquet29278 ай бұрын
  • I can't stop laughing at the thumbnail 🤣

    @Th3MoL3@Th3MoL38 ай бұрын
    • A real work of art. I'm pretty happy with how it turned out 😉

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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?

    @90vackoo@90vackoo8 ай бұрын
    • There's a method which you can call: ProducesResponseType So instead of an attribute, you call a method.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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.

    @Chris-zb5nm@Chris-zb5nm3 ай бұрын
    • "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

      @MilanJovanovicTech@MilanJovanovicTech3 ай бұрын
  • 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.

    @mad_t@mad_t7 ай бұрын
    • This is for APIs (it's in the name)

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • Does anyone measure the performance of controllers and minimal APIs, what is the difference?

    @pavelromashuk237@pavelromashuk2378 ай бұрын
    • I'll make a video about it!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech Cool. Looking forward!

      @pavelromashuk237@pavelromashuk2378 ай бұрын
  • what were you scared of in the thumbnail? :p , good vid

    @johncerpa3782@johncerpa37828 ай бұрын
    • The people defending controllers in the comments 😂

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Good stuff! I need to learn your presentation style, so to the point. What does the CarterModule internally do? Grabbing all those IEndpointBuilder usages?

    @kis.stupid@kis.stupid8 ай бұрын
    • Yea, basically. It's open source so you can view the code.

      @pilotboba@pilotboba8 ай бұрын
    • Maybe I'll implement a Carter clone in a future video to show how simple the concept is.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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

    @fahmiirfan6923@fahmiirfan69238 ай бұрын
    • Do you specify the entire route with controllers?

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@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

      @fahmiirfan6923@fahmiirfan69238 ай бұрын
  • Thanks for that one, I'll refactor my controllers asap 😅

    @MorethnaEdits@MorethnaEdits8 ай бұрын
    • Oh god, now your boss will be calling me 😂

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Minimal APIs when grows larger in size start to look like controller. Keep it minimal.

    @softcodeacademy@softcodeacademy8 ай бұрын
    • Endpoints should be minimal regardless.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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?

    @EugeneZavalko@EugeneZavalko8 ай бұрын
    • Will do!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech Thanks a lot. It would be interesting with roles.

      @EugeneZavalko@EugeneZavalko8 ай бұрын
  • I tried this but my JoyCons still won't reattach to my Switch 😛

    @EdKolis@EdKolis8 ай бұрын
    • Ah, crap! Unintended bug

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • This is very good, but how do I define FromRoute, FromQuery, FromBody using this?

    @figloalds@figloalds2 ай бұрын
    • You can use the attributes in the Minimal API request delegate ([FromQuery] MyQueryDto dto1, [FromBody] MyBodyDto dto2) => {}

      @MilanJovanovicTech@MilanJovanovicTech2 ай бұрын
  • 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.

    @Kingside88@Kingside888 ай бұрын
    • Carter helps so that you don't have to remember - it just works 😁

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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.

    @user-mm2no5kq2t@user-mm2no5kq2t2 ай бұрын
    • All else being equal, Minimal APIs have more throughput (= better performance)

      @MilanJovanovicTech@MilanJovanovicTech2 ай бұрын
  • Why? This looks like an invention of controller in perspective with increasing of complexity. Keep it minimal.

    @vasiliylu8054@vasiliylu80548 ай бұрын
    • How does it increase complexity?

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • 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.

      @vasiliylu8054@vasiliylu80548 ай бұрын
  • How much faster is this? Looks pretty unpolished and complicated compared to the controllers.

    @sokoo1978@sokoo19788 ай бұрын
    • 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.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech Awesome, I love to see video to compare the performance and memory allocation compare between controllers and minimal APIs.

      @detectiveice4110@detectiveice41108 ай бұрын
  • @techpc5453@techpc54538 ай бұрын
    • 👋👋

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • I like controller base api

    @livehole3635@livehole36357 ай бұрын
    • We all do 😁

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • 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.

    @khalilovk@khalilovk8 ай бұрын
    • 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

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • 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.

      @pedrosilva1437@pedrosilva14378 ай бұрын
    • @khalilovk they are finding problem to a solution. Lol

      @jessegador@jessegador8 ай бұрын
  • 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

    @kiran-Joy@kiran-Joy7 ай бұрын
    • That is true

      @MilanJovanovicTech@MilanJovanovicTech7 ай бұрын
  • Nice video mate. Still I don’t like this minimal api. I find it so damn annoying

    @zikkrype@zikkrype8 ай бұрын
    • That's fine, we have options in .NET and we can decide what works for our projects 😁

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • 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

    @magashkinson@magashkinson8 ай бұрын
    • 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.

      @pilotboba@pilotboba8 ай бұрын
    • 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

      @bobek8030@bobek80308 ай бұрын
    • 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

      @victor1882@victor18828 ай бұрын
    • @@bobek8030 Yes, I mean they are more performant during runtime.

      @pilotboba@pilotboba8 ай бұрын
    • @@pilotbobamy subjective opinion is BETTER

      @magashkinson@magashkinson8 ай бұрын
  • 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

    @yuGesreveR@yuGesreveR6 ай бұрын
    • What about cohesion? Minimal APIs make it easy to implement REPR

      @MilanJovanovicTech@MilanJovanovicTech6 ай бұрын
    • @@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).

      @yuGesreveR@yuGesreveR6 ай бұрын
  • 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.

    @UltraGameCoder@UltraGameCoderАй бұрын
    • That's true, a possible disadvantage

      @MilanJovanovicTech@MilanJovanovicTechАй бұрын
  • I just dont like this, idk why minimal and static api's like harding code. Is any performance testing on there?

    @selmangulmez6476@selmangulmez64763 ай бұрын
    • 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

      @MilanJovanovicTech@MilanJovanovicTech3 ай бұрын
    • Thank you milan!@@MilanJovanovicTech

      @selmangulmez6476@selmangulmez64763 ай бұрын
  • 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.

    @rogerstich7603@rogerstich7603Ай бұрын
    • 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

      @MilanJovanovicTech@MilanJovanovicTechАй бұрын
    • @@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.

      @rogerstich7603@rogerstich7603Ай бұрын
  • sorry no

    @S3Kglitches@S3Kglitches8 ай бұрын
    • Why?

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • @@MilanJovanovicTech for large real world apps it's unusable and unmaintainable

      @S3Kglitches@S3Kglitches8 ай бұрын
    • @@S3Kglitches If anything it's easier - because the dependencies for each endpoint are clear. In a controller, all dependencies are shared between endpoints.

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
  • Seriously? Converting Controllers to minimal APIs? You are finding problems with a solution.

    @jessegador@jessegador8 ай бұрын
    • Someone out there will want to migrate from controllers to Minimal APIs

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • 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.

      @krccmsitp2884@krccmsitp28848 ай бұрын
  • 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.

    @allannielsen4752@allannielsen47528 ай бұрын
    • I'm sorry you feel that way. I wish you a heartfelt goodbye. Stay awesome!

      @MilanJovanovicTech@MilanJovanovicTech8 ай бұрын
    • What a bizarre comment. Grow up dude.

      @sneer0101@sneer01018 ай бұрын
    • 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

      @wmalgoire@wmalgoire8 ай бұрын
    • @@wmalgoire Not speaking for the OP, but maybe because of the word "Fix". There's nothing "broken" about controllers.

      @pilotboba@pilotboba8 ай бұрын
    • 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.

      @allannielsen4752@allannielsen47528 ай бұрын
KZhead