Choosing between MVC Controllers, Minimal API, or FastEndpoints for C# APIs.

preview_player
Показать описание
Not sure whether your .NET API should use MVC, minimal API, or something else? Let's talk about the pro's and con's of each and compare them with Fast Endpoints as another alternative.

Don't forget to comment, like and subscribe 🚀

💬 JOIN US ON DISCORD

00:00 - Let's do this!
00:29 - ASP.NET MVC Controllers
01:42 - ASP.NET MinimalAPI
02:41 - FastEndpoints

🧑‍💻 LET'S CONNECT ON SOCIAL

#dotnet #csharp
Рекомендации по теме
Комментарии
Автор

I've turned into a FastEndpoints superfan. What were your last few .NET API's written in?

BaldBeardedBuilder
Автор

Hey,
I love the video, it gives a fast overview over the different options for creating web api endpoints.
Also I didn't know about fast endpoints, thanks for explaining that !
However, I would love to touch on something that you didn't quite mention in your video.
There is an attribute for the controller based approach that's called "FromServices" using that attribute you can inject dependencies into the individual methods instead of injecting them over the controllers constructor and having the mentioned downside of executing logic to fetch a certain service but not actually needing it. So that is not really an advantage of minimal APIs.

mitar
Автор

From a code organization standpoint, Controllers can often end up being "dumping grounds" in so much as we tend to align controllers with Entities in the DB, and developers will try and fit in. Ie. WidgetController "well, we need to get a report on the number of widgets sold, let's stick it in the WidgetController". And not to say you can't have the same situation appear with Fast Endpoints, but from the examples I've seen so far, endpoints are based more around the actions with verbiage (I won't go so far as to say restful), so even if a behavior does get misplaced, it's much easier to see and much easier to move.

tbddevelops
Автор

I love Fast Endpoints. I've used it on a few side projects over the last couple of years.

bitobrian
Автор

Switched from MVC/Web API to Fast Endpoints 2 years ago and haven't gone back. It's improved a lot in that time too.

reikooters
Автор

Where I work we use MVC controllers and MediatR (along with fluent validator and other middleware). If I was to do another app I would switch to minimal API and MediatR, or checkout fast endpoints as it sounds very similar.

renynzea
Автор

Love the minimal api approach, I have a large minimal api in development, now I'm wondering if I should checkout FastEndpoints. How difficult would it be to migrate and existing MinimalAPI to FastEndpoints? Fortunately, maintaining client compatibility is not a requirement yet.

Reservations:
- Don't want to get locked into a 3rd party platform
- Client Code generation, we autogenerate C# client libraries from the api swagger spec, can we do this with FP?

blackpaw
Автор

I use Minimal API with static methods, gives me all the same benefits as controller classes, without some of the drawbacks
You can in fact use comments with Minimal API, just map a static method rather than a lambda :)

docpify
Автор

Minimal API doesn't expect the endpoints to be in one class. A good option is to move them into their own file for logical groups and use the group option. Use an interface with a register method to set them all up and then use an extension method to search the assembly for those Interfaces and call the registration method on each.
Voila, potentially tens of files with hundreds of endpoints well structured and nicely registered.

harrisonbs
Автор

So if I put every controller endpoint in a separate class, I'd get the same perf as minimal API?

JackBauerDev
Автор

i disagree that, for Controllers, DI is only at the controller level — you can inject a service into a method with [FromServices] attribute on a parameter.

burtonrodman
Автор

Wow since when did you switch to dotnet? I really like the tech and C# but I'm so much in TS that I can't find a good usecase

MaxProgramming
Автор

Wrong about dependency injection in controllers. You can inject them in each controller action.

svorskemattias
Автор

Shocked face thumbnail? Does it still work? I thought we were quite past that phase. Maybe it’s time to try something new. Like stick your tongue out or pick nose booger to rope in viewers.

mubashir
Автор

The statement that minimal APIs must live in one class is patently false.

terjeber