Good afternoon everyone, I'm learning ASP.NET Core 2.0 And I came to a section where a class is created to use it as a repository "Repositorrio.AddResponse(Object Received)"
1-) What is the function of repositories? What are they for?
2-) What function does the "AddRespose"() method do?
so that it is added to the Startup file in the "ConfigureServices" section
Please explain it in a simpler way, I just read the documentation and I still don't understand
public static class Repository
{
private static List<Estudiante> responses = new List<Estudiante>();
public static IEnumerable<Estudiante> Responses
{
get
{
return responses;
}
}
public static void AddResponse(Estudiante estudiante)
{
responses.Add(estudiante);
}
}
}
The repositories are the means by which you are going to obtain / insert information, it can be, as in your example, a
List<T>
defined in the program, as well as the connection logic to a database, from which you would obtain, you would modify and insert informationI'll explain, in the code
What you are doing is adding the student that you receive as a parameter to the list
List<Estudiante>
that you declare above.and in the method
What you are doing is returning the same list that I mentioned above, in this way, you could, for example, receive it in a view, to show the information of all your students in a table
Anything you don't understand from what I'm telling you, don't hesitate to ask in the comments