The repository and unit of work patterns are used to create an abstract layer between data access layer
and the business logic layer. This can help to insulate application from changes in data store and also help in test-driven-development (TDD).
In this post, I have implemented a repository class for entity type "User" creating a repository interface and a repository class.
When we instatiate the repository in the controller, the interface will accept a reference to the object that implements the repository interface.
1. When the controller runs under web server, it receives a repository that works the Entity Framework.
2. When the controller runs under a unit test class, it receives a repository that works with either in-memory data or a mocking database which can be easily manipulated for testing.
The unit of work class wraps the work of multiple repositories by creating a single database context class shared by all.