-3
I came across a question, I have a very simple project here with three entities, being they Teacher, Student and Class.
I created the classes at Model. Example
namespace coreSchoolSimple.Models
{
public class Professor
{
public int Id { get; set; }
public string Nome { get; set; }
public string Email { get; set; }
public string Telefone { get; set; }
}
}
For me to do CRUD, I have three options.
1-If I use VS 2017 to generate the controller with views and EF, it creates the controller already with the complete CRUD logic for me, but the logic is inside the Controller.
2- Create the controller blank, and the logic of CRUD is inside the class of each entity, example: in the Teacher class will have the methods Create, Delete, Insert and List.
3- already in this option is to create a folder called service in the project root, and make the logics within a class in this folder, and use these classes as a service for each entity, example: Professorservice.Cs will have the methods of crud. And I use it as a service.
My only question is: Is there any difference between these forms outside the question of organization? For example performance or good practices?
Root of the Project:
There’s a difference, obviously, if I didn’t, it would be the same thing. Performance generally no, good practice does not serve nothing if it does not meet a specific motivation, and without concrete case edge to opinion. Do you have any specific doubt?
– Maniero
Yes, let’s say that I have several other methods to do (besides crud) for example calculatMediaNotas(), I must do in the respective entity class or do in another service class, I am asking this because I am starting my studies, and I want to do it in the right way.
– Renan
And how do we know we don’t understand the whole context of your software? For some reason you think there are magic answers (I was already suspicious of believing in good practices) so you want someone to say "do it like this and everything will be beautiful", this does not exist. There is no right way without understanding the context that is working, that only you know.
– Maniero
What context did you not understand in my question? tell me so I can clarify.
– Renan
There’s nothing to understand, because there’s no context, only you know its context.
– Maniero
I closed as P. B. Opinions by several extremely subjective elements (the example of the answer given), but would qualify as broad and unclear, given the lack of parameters and the subject very "informal conversation" (in the good sense, because it is something for a conversation and not Question + Objective Answer) - Considering that your score already allows, it would be the case to raise these doubts initially in the network chat, and as the scope focuses on one-off problems, elaborate separate questions on each of these points.
– Bacco