✅ I need feedback to try to improve [.Net API]
Hey, I'm studiyng a lot of .Net backend in this year and I have applied for a lot of intern and junior positions recently. I did a lot of tests, but most of them don't give me any feedback :/
I need anyone good at .Net API that can check a repository, I'd really appreciate feedback on what I'm getting wrong and what I need to improve and study. I know I'm just a beginner.
Studying is important, but without feedback I feel directionless.
I'd like feedback on my last test:
https://github.com/Jvramiro/tech-test-backend-csharp
Sorry about the readme in portuguese, I'll try updating to two languages
And sorry if this is the wrong place to post it :/
9 Replies
It's weird that you select the database that should be used when creating a product
It's usually not how it works
If (and that's a big if) you plan on the database to be swappable, you create some sort of a repository and inject that
So you would have a service that gets a
IDatabase
of some sort
And then you would .AddScoped<IDatabase, SqlDatabase>
or .AddScoped<IDatabase, MongoDatabase>
etc as needed
That would be how you switch data sourcesYou could use FluentValidation for the validation so that business logic is abstracted away from your controller.
You could use Mapping to map Request Object -> Domain Object -> Response Object
Why you'd want to do this is to provide the consumer a contract they can follow (a blueprint if you want) on what to send and what to expect.
In the end your
Create
endpoint could look someting like this:
additionally, you might want to have your CreateProduto method return a Task
instead of void
(async void) (I would also rename that method to something like CreateProdutoAsync
<:zerotwo_shrug:841954087238107186>Oof, I didn't even notice that
async void
. Yeah, that's a big no-noThanks, I really need to study and use Interfaces more
Hmmmm that async void was from a course that I studied, thanks ^^
async void
is typically used in UI applicationsNick Chapsas
YouTube
Stop using async void in C#! Do this instead.
Use code REST15 for 15% off the new From Zero to Hero - REST APIs in .NET course: https://bit.ly/restchapsas
Become a Patreon and get source code access: https://www.patreon.com/nickchapsas
Hello everybody I'm Nick and in this video I will show you why you should not be using async void in C#. It is a very common mistake that can have very cat...
Nice, I'll watch
tl;dr: unless you're working with a desktop UI framework like WPF or Winforms,
async void
should be banned from the codebaseWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.
Was this issue resolved? If so, run /close
- otherwise I will mark this as stale and this post will be archived until there is new activity.