Тёмный
No video :(

How To Organize Minimal API Endpoints Inside Of Clean Architecture 

Milan Jovanović
Подписаться 99 тыс.
Просмотров 40 тыс.
50% 1

Опубликовано:

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 122   
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Get the source code for this video for FREE → the-dotnet-weekly.ck.page/organize-minimalapis Want to master Clean Architecture? Go here: bit.ly/3PupkOJ Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt
@mylesdavies9476
@mylesdavies9476 Год назад
I would really love to see a video on expanding the clean arch project into a collection of projects with their own endpoints (modular monolith) exploring how to communicate between the different modules
@AboutCleanCode
@AboutCleanCode Год назад
maybe this is helpful for you ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-1IE8RC-IOSE.html
@MilanJovanovicTech
@MilanJovanovicTech Год назад
That's on the radar, I just need some time 😁
@kodindoyannick5328
@kodindoyannick5328 6 месяцев назад
Your contents are always very rich for me. I really appriciate them. Thank you Milan
@MilanJovanovicTech
@MilanJovanovicTech 6 месяцев назад
My pleasure!
@stephenraphael6911
@stephenraphael6911 Год назад
Hi Milan, I would like to THANK you for your effort sharing your knowledge and research information you share with us. I found this video very very useful for me cause I currently started an project with Minimal API and here is exactly what I needed to resolve. Hope you'll continue to provide new videos & tutorials to US. Thanks again!
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Great, happy to hear it helped someone
@ferventurart
@ferventurart Год назад
Thanks for share Milan! I hope in the future you will talk about DTO and Mapping with entities inside of Clean Architecture!!
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Perhaps, I don't think it's a "big" topic though
@tryagain6148
@tryagain6148 Год назад
4th option - go back to the controllers, as all these approaches are actually ways to mimic the same outcome. 5th option - structurize it like you'll do it in expressJs My 2 cents regarding this one - minimal API is great when you have just few endpoints, but when you will get to 100 (the reference number you used) is better to stick to the controllers. This might be subject to an ADR (architecture decision record) in a real world project 😉
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I'm just wondering why you think endpoints are so different from controllers that maintaining 100-200 endpoints would be any different? 🤔
@tryagain6148
@tryagain6148 Год назад
From the Microsoft documentation: "Minimal APIs are architected to create HTTP APIs with minimal dependencies. They are ideal for microservices and apps that want to include only the minimum files, features, and dependencies in ASP.NET Core." With this in mind and the fact that the controllers already offer a well-known, and mature, oriented around functional parts it's easier to scale the development and maintainability. Also from the security point when talking about authZ is easier to tackle this at the controller level than in the minimal API approach. Unit testing the minimal approach it's possible depending on the approach, but feels unnatural, and this is probably for the best as the API layer should be devoid of any application or business logic and should focus primarily on a few concerns. What I do not like at the controllers is the fact that I get all dependencies for functionalities I do not require in specific flows, and in the minimal API this is already "fixed". Considering the fact that you have between 100-200 endpoints in an API I would question its architecture. Is this a monolith, or is an API domain oriented which should do only that specific stuff and nothing else?!? As an example dealing with customers means you need to be able to create, update, delete, disable, filter, and find a customer - this will be roughly 10 possible endpoints. Of course, in some cases, the situation might be a bit more complicated than that but that will depend on the given context. So as always in software architecture everything is a tradeoff as you will win some, and you will lose some ...
@grumpydeveloper69
@grumpydeveloper69 Год назад
I thought about 4th option at first as well. This looks to restore the (Api)Controller behaviours that were avaiable there. But Minimal API's are more of an opt-in setup whereas Controllers gave you everything, even when you didn't need it. So, yes this video tries to restore some of the behaviour that was already present in controllers, but NOW you get it in a leaner way where you only get/use the things you are interested in. It's not that controllers were bad, it's just they gave you -- in certian use-cases -- a lot of things you did not need. @Milan Nice video, you always make me think twice (or more) on what you explain and most of the times, even when I don't agre at first I have to revise my opinion and DO agree whit what you say. Keep up the good work, I really enjoy your videos
@ihorvelychko5254
@ihorvelychko5254 Месяц назад
Thanks for the great content. I've watched some of your videos about clean architecture which helped me a lot to understand the topic.
@MilanJovanovicTech
@MilanJovanovicTech Месяц назад
Awesome, happy to help! :)
@geochavarria8214
@geochavarria8214 9 месяцев назад
One of my problems was: How to maintain a minimal segmented API? Thanks for this video
@MilanJovanovicTech
@MilanJovanovicTech 9 месяцев назад
Glad it was helpful!
@geochavarria8214
@geochavarria8214 9 месяцев назад
Now, How to implement Versioning with Carter? or Not Apply this method@@MilanJovanovicTech
@mionel237
@mionel237 Год назад
great stuff. do some videos on cloud(azure) related work. like function apps, working with storages, best practices, project set up etc. great stuff as greatness comes from awesomeness :)
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I have all that planned, don't worry. Just can't release 20x videos in a day 😂
@imranyaseen7880
@imranyaseen7880 Год назад
I always wait for your videos. Your videos are full of information and the way you explain is simply awesome!!!
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Thank you so much 😀
@88spaces
@88spaces 6 месяцев назад
Hi Milan, looks clean and like a winning plan. The latest version includes support for authorization which is a must have. I'll try it in my new project.
@MilanJovanovicTech
@MilanJovanovicTech 6 месяцев назад
Take a look at this for a simplified implementation: www.milanjovanovic.tech/blog/automatically-register-minimal-apis-in-aspnetcore
@gavincampbell1061
@gavincampbell1061 Год назад
@4:05 If you make the IModule's RegisterEndpoint abstract static then your ProductsModule can remain a static class, so you don't need to create an instance of it to register the endpoints.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
What would that imply when fetching the implementations of IModule? 🤔
@gavincampbell1061
@gavincampbell1061 Год назад
@@MilanJovanovicTech I mentioned it as you said you had to change the ProductsModule to no longer be a static class so it could implement the interface, but that is possible using abstract static in the interface. But why it might be useful in this scenario is that not creating an instance would avoid the need to garbage collect them afterwards. As the project grows and you potentially have lots of Modules, that clean up after scaffolding could slow down your start up time, which is less than ideal in a serverless setup for example. The performance hit might be negligible, but if what you're doing can be done without requiring an instance then it's an option.
@lalibi
@lalibi Год назад
Hi, great content! Could you elaborate on the `request.Adapt` approach? Is `.Adapt` just an extension method?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Yes, and it comes from the Mapster library to do a dynamic mapping
@kevinbeye6263
@kevinbeye6263 Год назад
First vid I've seen, good structured info, really like to get into the clean architecture and minimal API's (as others said it's on the hype train nowadays). Still not sure how this would work with the microservice architecture which I'm also a fan of, as it feels like a lot of different functionality would go into a minimal API when you have 100-200 routes lol
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I think I'll have to expand on this project to beef it up with a lot of endpoints, and then we'll see if I start hurting 😂
@kevinbeye6263
@kevinbeye6263 Год назад
@@MilanJovanovicTech Hehe looking forward to it😁 but what is your thoughts on microservices vs minimap api's?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
@@kevinbeye6263 Well, microservices are a system architecture. Minimal APIs are a just a way to implement endpoints. How do we compare them?
@CodingWithSaba-yi8uj
@CodingWithSaba-yi8uj 4 месяца назад
what's the diference between carter and just using controllers?
@MilanJovanovicTech
@MilanJovanovicTech 4 месяца назад
Minimal APIs
@HNoriega
@HNoriega 5 месяцев назад
Hi Milan, I really apreciate it your content, its just that i need. I have a question... Carter support Native AOT?
@MilanJovanovicTech
@MilanJovanovicTech 5 месяцев назад
No idea
@velkumars26
@velkumars26 Год назад
Its really great Milan. @Milan, is there any way to Implement endpoint for specific roles like [Authorize(Roles="role1,role2")] ?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Yes, you can apply the Authorize attribute to the endpoint lambda expression. Or you can call the method on the IEndpointRouteBuilder to add authorization
@Tamer_Ali
@Tamer_Ali Год назад
Thanks Milan, you awesome. keep it up 👍
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Thanks, will do!
@seasonaldeveloper5882
@seasonaldeveloper5882 Год назад
I cant seem to find the CarterModule. I installed Carter Library version 6. Great vids btw.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Strange?
@ezmooj
@ezmooj 11 месяцев назад
Thanks
@MilanJovanovicTech
@MilanJovanovicTech 11 месяцев назад
Don't mention it ;)
@swedishmichaell7369
@swedishmichaell7369 Год назад
Thanks for a great video!
@MilanJovanovicTech
@MilanJovanovicTech Год назад
You're welcome :)
@antonmartyniuk
@antonmartyniuk Год назад
Have your tried the FastEndpoints library for organising minimal APIs? Which one do you like more?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I didn't try it
@nomad191
@nomad191 Год назад
Nice video. I have a small question, Why do we need the 'this' keyword before the IEndpointRouteBuilder?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
That's how you define an extension method on the IEndpointRouteBuilder interface.
@nomad191
@nomad191 Год назад
@@MilanJovanovicTech Thanks !!
@ramytawfik9168
@ramytawfik9168 Год назад
Another question please, what are the significant Pros to use minimal APIs instead of Controller APIs ?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
There are none - except if you need advanced IFormFile support
@ramytawfik9168
@ramytawfik9168 Год назад
@@MilanJovanovicTech Thanks Milan
@BandieraRossa87
@BandieraRossa87 5 месяцев назад
Does it make sense to rely on a 3rd party library like Carter to achieve a (in my opinion) rather trivial task like registering the routes automatically? Assuming we have an API with 100 endpoints that are divided in modules of 5 endpoints each, this would mean adding 20 lines of code to Program.cs to add the endpoints. Or is the fact that Carter allows you to add things like authorization, cors, rate limiting, etc. the real benefit of this library?
@MilanJovanovicTech
@MilanJovanovicTech 5 месяцев назад
I've used carter for this, or a simpler implementation: www.milanjovanovic.tech/blog/automatically-register-minimal-apis-in-aspnetcore
@BandieraRossa87
@BandieraRossa87 5 месяцев назад
What's the purpose of the "Presentation" project? Do I correctly assume that it's meant to keep the "WebApi" project as thin as possible and make the logic of the Presentation project reusable for other WebApis?
@MilanJovanovicTech
@MilanJovanovicTech 5 месяцев назад
You can also merge the API and Presentation as one project
@guava_dev
@guava_dev Год назад
I feel like I'm the only person that doesn't like the minimal API approach. I get they're more performant, however, I find controllers far more readable. Not to mention they remove the need of something like Carter
@peterkulik5943
@peterkulik5943 Год назад
The main problem with your attitude: Minimal API is on the hype train. Sooner or later you can't skip it... :D
@MilanJovanovicTech
@MilanJovanovicTech Год назад
How is a controller endpoint any different from a minimal API endpoint? I don't think there's any significant difference.
@aliwa91
@aliwa91 Год назад
Me to i don't like minimal api but I used in small project only
@alamzaibfarooq
@alamzaibfarooq Год назад
I would prefer controller over minimal endpoint.
@Roon3y
@Roon3y 10 месяцев назад
Just create a controller class that contains your endpoints. I've used MVC APIs for 10 years now and minimal API has been brilliant. No bloat, exactly what I need, if I like controllers then I can still use them (not sure why though). 100% control and everything is visible unlike MVC style with its magic. Just my opinion
@cutefunnyanimals5876
@cutefunnyanimals5876 Год назад
I'm fine with doing 1 action but what if I need to call more than 1 action like CreateInvoice + UpdateUserPayment + UpdateHistory? Do you need to create new handler to combine all these 3 actions or call mediator.Send() thrice with these 3 handlers in api endpoint?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
You can either send 3 commands, or raise events after each command completes and process it later.
@enricoroselino7557
@enricoroselino7557 8 месяцев назад
i ended up making endpoints folder at the api project, cant resolve the dependency on Presentation layer bcause not reference assembly something something
@MilanJovanovicTech
@MilanJovanovicTech 8 месяцев назад
That's fine
@stunna4498
@stunna4498 Год назад
nice video once again my main problem with minimal apis is that microsoft is trying the "node" way of building apis and for me doesn't really suit it. I will only use this if im doing a hobby project or trying stuff up but in a real world enteprise application im not really using it. Whats your thoughts on that?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I'm honestly liking Minimal APIs more and more. My controller endpoints are simple always, since I often use MediatR. Minimal APIs make this process even easier.
@the-nasim
@the-nasim Год назад
We now have MapGroup feature, so all the advance configuration that Carter provides are not necessary.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Indeed! I do believe that's what Carter uses under the hood
@IpsianNeo
@IpsianNeo 8 месяцев назад
Why "IEndointRouteBuilder" not found in presentation layer?
@MilanJovanovicTech
@MilanJovanovicTech 8 месяцев назад
Is it not?
@jeffersantosss
@jeffersantosss Год назад
How to organize the external API calls in Clean Architecture? It would be nice to see how you deal with…
@MilanJovanovicTech
@MilanJovanovicTech Год назад
In the making!
@phoenicianathletix2866
@phoenicianathletix2866 Год назад
If a cms thats Modular Monolith use Minimal API Endpoints will that help increase application speed, performance, lower latency or is it mainly to prevent the spaghetti code?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Minimal APIs are more performant than controllers
@phoenicianathletix2866
@phoenicianathletix2866 Год назад
Thank you
@nezqwe4818
@nezqwe4818 7 месяцев назад
Hi, in the carter module. How do you add the logging? Please help! I can't DI logger.
@MilanJovanovicTech
@MilanJovanovicTech 7 месяцев назад
Why not?
@nezqwe4818
@nezqwe4818 7 месяцев назад
@@MilanJovanovicTech I sort of figured it out. i need to use "this" keyword in order to DI the logger. Instead of _logger = logger it needs to be this._logger = logger.
@grm360
@grm360 Год назад
Is there an easy way to use [FromForm] and [FromQuery] with Minimal Apis?
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Yes, works the same as [FromBody]
@phaing1471
@phaing1471 Год назад
Great Job!!! Thanks for introducing the Carter Lib. BTW i m interested in howto apply the feature flagging especially using the FeatureGate attribute.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I'll make sure to cover feature flagging soon!
@ryoman76
@ryoman76 Год назад
you are a great
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Thanks!
@Nekr0n666
@Nekr0n666 Год назад
Thanks for the great content Milan. Have you used the FastEndpoints nuget package? I think it's a great alternative for structuring minimal apis, comes with a nice collection of features out of the box, definitely worth checking out if you haven't before.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I haven't tried it, but I took a look at the documentation. I didn't like the additional ceremony required to define endpoints.
@maxpuissant2
@maxpuissant2 Год назад
I thought the minimal API would only be used when your API has less than 10 endpoints and all the Presentation layer can live in Program.cs, I don't see the point of not using the controllers passed that.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
They are more performant than controllers. And if your controllers are "thin" you may as well consider using Minimal APIs.
@maxpuissant2
@maxpuissant2 Год назад
@@MilanJovanovicTech if we add Carter and all on top of minimal API I'm curious if they really stay more performant but quite frankly I don't care that much about performance. If controllers are thin enough I will happily use minimal API or put them all in one controller.
@stasasekulic6917
@stasasekulic6917 10 месяцев назад
I am using command validators, and after I have tried to add Carter, I was not able to fix DI problems with scoped,... Could you show some example of how to use Carter if your CommandHandle have a CommandHandlerValidator that inherits AbstractValidator
@MilanJovanovicTech
@MilanJovanovicTech 10 месяцев назад
That seems to me like it's completely unrelated to Carter. Carter only registers your minimal API endpoints, right? And you register MediatR/FluentValidation separately?
@stasasekulic6917
@stasasekulic6917 10 месяцев назад
I am trying implement Clean Architecture. I have followed all the instructions from one of the online courses up untill controllers. I wanted to implement minimal API instead of controllers. I did that successfully in the program.cs. And then when I wanted to refactor, problems started. I did successfully by separating in the static classes as you explained at the start of video. Then I wanted to "migrate" to carter solution. At that point "Some services are not able to be constructed"..."Cannot consume scoped service"..." from singleton 'FluentValidation.IValidator'.)" errors appeared, even if my carter modules were empty. Using addCarter and mapCarter was enough to cause those problems. I am registrating MediatR and Automapper in the ApplicationServiceRegistration And I am registrating repositories in the Persistence part as AddPersistenceServices. For Validators I have used AbstractValidator. I presume it is due to scopes, but I think I have tried almost every combination but without success... Thanks in advance :) @@MilanJovanovicTech
@ramytawfik9168
@ramytawfik9168 Год назад
Hello Milan, hope you are well. you state before that you make a presentation layer as the benefit is just a little stricter control of what you can do in your endpoints. But inside the Presentation Layer you still can inject for example ApplicationDbContext so i see that you make a control strict on the web api project itself but still can break the clean architecture in the Presentation Layer
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I'd say that was just an example, and not the correct way to use it
@lasindunuwanga5292
@lasindunuwanga5292 8 месяцев назад
I would say, Made a full circle back to controllers 🙂
@MilanJovanovicTech
@MilanJovanovicTech 8 месяцев назад
But the performance aspect is different, and some other nuances of Minimal APIs
@lasindunuwanga5292
@lasindunuwanga5292 8 месяцев назад
@@MilanJovanovicTech and minimal apis has limitations even in .net 8 When they came first I thought this is made for micro services.
@JebenOvajIgrac
@JebenOvajIgrac Год назад
Da li dajes privatne casove za C#
@MilanJovanovicTech
@MilanJovanovicTech Год назад
Nažalost ne :)
@akrotiri3246
@akrotiri3246 2 месяца назад
I am going to have a lot of endpoints, how about not using minimal api?
@MilanJovanovicTech
@MilanJovanovicTech 2 месяца назад
The number of endpoints doesn't change between controllers and Minimal APIs
@JCode00
@JCode00 Год назад
Hi, Do you have source code, in gittube, please, I'd like to exercice! Good, channel, help me to enhance my code. Portugal
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I share the source code on my Patreon
@sotsch9280
@sotsch9280 Год назад
The Presentation folder is the wrong place for the API endpoints. They belong to the Controller side, because they are Input Adapters.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I'd disagree
@sotsch9280
@sotsch9280 Год назад
@@MilanJovanovicTech the point is that your agreement is not necessary. You speak about clean architecture, which has clear Rules about what to place where. There are Input Ports and Output Ports in the Interface adapters layer. And also there are Presenters implementing the Output Ports and Controllers calling the Input Ports. Putting the API endpoints to the Presentation side just confuses, because they belong naturally on the calling side to your use cases / Application. I Like your content but this feels not intuitive.
@redstrike91dn
@redstrike91dn 7 месяцев назад
At first sight, I think it's weird because I'm not familiar with Clean Architecture folder structure. However, it's correct that the API endpoints' mapping code should be in the Presentation layer. The endpoint handlers act similar to Controller methods. Besides, HTTP APIs are not the only way to interact with an API service. WebSocket APIs have their own message handlers too. They can share common logic by calling service classes' methods.
@bahtiyarozdere9303
@bahtiyarozdere9303 Год назад
I do not see the benefit of adding a presentation project and registering api endpoints in it instead of web api project itself.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
You're moving away the API definition from the Web projects which has to stich all the service together for DI. That way, you Presentation layer will only have access to the Application layer commands/queries. The benefit is just a little stricter control of what you can do in your endpoints.
@tryagain6148
@tryagain6148 Год назад
This works great for small projects but when talking about enterprise level solutions you will need to rethink it. You will prefer assembly scanning and dynamic loading over stitching everything in the same project as it can it can scale easily, easier to develop and maintain. This is a great way of benefiting of the DI, abstractions and independent modules. As idea you can get several microservices and just start them from the main process as a monolith, or you can use them independently - when comes about cost the stakeholders will require cheap solutions with the max outcome.
@anatolia23
@anatolia23 Год назад
Zero advantages! I'm constantly amazed by how much people like overengineering.
@speakoutloud7293
@speakoutloud7293 Год назад
Show less face, and no subtitles word by word. This video is about tech stuff and not colorful subtitles word by word.
@MilanJovanovicTech
@MilanJovanovicTech Год назад
I'm the one deciding that, but thanks for your tip.
@speakoutloud7293
@speakoutloud7293 Год назад
@@MilanJovanovicTech yeah of course you decide that, obviously that's not my video lol.
Далее
Fix Your Controllers By Refactoring To Minimal APIs
14:56
In defence of .NET Minimal APIs | Refactoring
14:25
Просмотров 57 тыс.
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Просмотров 760 тыс.
How to get Spongebob El Primo FOR FREE!
01:36
Просмотров 13 млн
How To Use Domain-Driven Design In Clean Architecture
30:27
Vertical Slice Architecture Project Setup From Scratch
22:43
How To Create Smart Enums in C# With Rich Behavior
17:31
Forget Controllers and Minimal APIs in .NET!
14:07
Просмотров 67 тыс.
Should I Create A Minimal API Or Full API?
7:40
Просмотров 36 тыс.
The Logging Everyone Should Be Using in .NET
15:34
Просмотров 64 тыс.
ПРИКОЛЫ НАД БРАТОМ #shorts
00:23
Просмотров 760 тыс.