Clean up your .NET Controllers with ApiEndpoints

preview_player
Показать описание

Hello everybody I'm Nick and in this video I will show you an alternative way to build an elegant API in ASP.NET Core using ApiEndpoints, a nuget package created by Steve "ardalis" Smith.

Don't forget to comment, like and subscribe :)

Social Media:

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

Great video as always!
Want to note something for those who're struggling with controllers having too many dependencies. There's this useful attribute [FromServices], that will allow you to inject only the required dependencies in your controller method, e.g.:
public logger){ }

public IActionResult GetPictures([FromServices] IDatabaseService databaseService){
return
}

public IActionResult UploadPicture([FromForm] IFormFile file, [FromServices] IPictureService pictureService){
return
}

Sirozha
Автор

We've been using Ardalis Endpoints for a year+ and pretty happy with it. Every method has its own "pipe". It means I don't don't touch the methods whose logic hasn't changed and I can see clear dependencies for each endpoind. It's much better than the controller, which usually has tons of dependencies and it's not easy to understand what depends on what after some time. Thanks for the video, now I'm more confident that we made a right chose.

Dimonina
Автор

NO! Let us not find the solutions for the problems that do not exist. But other than that, this was really well made explanation of a (not needed) package. Loved watching it.

zoran
Автор

I don't see what it delivers except of separation of each method from the one domain controller in each own little controller. Actually it is a lot of duplicate code. Id rather introduce an usecase specific ApplicationService in between the controller- and the server-layer.

larryd
Автор

ApiEndpoints is built on top of mvc controllers, it would be nice to have a comparative with FastEndpoints that is built on top of C# minimal apis

jcorrify
Автор

You and Steve are probably my favorite .NET content creators/instructors. I've learned so much from both of you over the past few years. Great work, both of you!

AJax
Автор

I could maybe misunderstand the problem this project is trying to solve, but if you want to split up your controller to have cleaner code, couldn't you just create partial classes with each their own file name in a folder?

Albileon
Автор

Notification gang! Black coffee and Nick sharing generously is a sweet combo

ifeanyii
Автор

Damn, I literally stumbled across the repository of this project today and here is your video XD

vorontsovru
Автор

Very similar to a serverless approach. Nice I like it

MauricioSierra
Автор

Would be great to show how "testable" a new framework is when demoing it.

Keep up the good work.

liquidvapour
Автор

I don't see this package that much more elegant than the current controller architecture out of the box. The only real thing you gain here is a little better code structure.

seephor
Автор

this similar mindset with mediator pattern maybe would be very useful when working on a complicated legacy project where you would step by step recreate into an app. again, thanks for sharing

tuberklz
Автор

Man, Nick you rock. I will definitely check this out.

josephizang
Автор

Well, what can I say, first we make difficulties for ourselves and then we heroically defeat them.

vifvrTtbvmFtbyrM_Q
Автор

in the past I used to split controller actions using partial classes which would help a lot merge conflicts and keep things organized. I didn't know about this template, I will give it a try in my next projects. Thanks for sharing

thc_
Автор

I looked at this ApiEndpoints library and then I thought, well based on the nice isolation of this approach why not just skip both the ApiEndpoints and Mediatr and just have your Controller, Request and Response Dtos in a single folder. Your controller only has one endpoint (Action Result) and only has injected services it uses, and it all looks like you generic controller but you don’t have any dependencies just plain old .net stuff. With this approach I got rid of Mediatr which although pushed things from my controller nicely, I still had one controller with many endpoints (Action Results). You don’t only have to have controller in a web project because its just a nuget package and with custom routing you can keep all customer related endpoints under the same [controller]/[action] style but there all in their own folders following the slice architecture patter quite nicely too. Been working for me for a few months now so quite happy

PoetNoPoems
Автор

What I really like about your videos is that when they are opinionated, you point out that it is opinionated and that there are other ways of doing this that people may prefer. So many YouTubers don't do this and it frustrates me and leads me to think that they are purposefully biased and misleading.

antibioticaddict
Автор

Interesting library, but at the end of the day it all depends on the agreements in the team. Usually What worked for my projects is separating write endpoints to their separate write controller and read controller

rvladkent
Автор

Great video! Was just wondering what font you use ?

NealAnthoons
visit shbcf.ru