Dotnet code generator web api question
I've been trying out the API code generator in visual studio/dotnet, and I had a question about some of the CRUD methods it generates:
What's the purpose of checking if
_context.Vehicles == null
? Like I understand that you obviously won't be able to add and saveChanges if it were null, but I can't think of a circumstance where it would be null and that check would apply? I see that check is done in Get, GetById, Post, and Delete. Just curious!9 Replies
It's useless. The generated code is dogshit
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Why would you want repositories, when DbContext is a repository?
Just use that directly in your services
There seems to be a great divide in this discord between using dbcontext directly in the controller or using it in a service. Noticed that almost daily 😆
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'm on the side of calling my service class from my api controller, but as I mentioned. Great divide. I got told the other day that calling to my service classes was useless and that I should just do it in the controller. I was under the impression that violated SRP etc, but hey ho
Frontend > API > Service (inc business logic, mapping, dbcontext) is how I usually go
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Guessing your DAL is literally just methods that use the dbcontext?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View