...

/

Implementing a Repository

Implementing a Repository

Learn how to implement a repository in your ASP.NET Core application.

Repository interface

To implement a repository in your application, you need to start with implementing a repository interface. This interface will hold all method definitions that need to be implemented. For now, you are only focusing on CRUD operations.

Press + to interact
public interface IUserRepo
{
User CreateUser(User user);
IEnumerable<User> GetAllUsers();
User GetUserById(int id);
User UpdateUser(User user);
User DeleteUser(int id);
}

It is a convention in C# to have your interface’s name start with the letter “I” as a prefix. Since this repository is going to be responsible for the User model, it is being named IUserRepo, and it has written all of the methods required. ...