Latest posts tagged on "MVC"

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.


Any public method in a controller can be called as an action. Usually actions returns any type that derives from ActionResult. 

Similarly, ViewResult is also a action that is heavily used to return from any public method in controller as return type. View Models are classes specially created for views. They contains properties related to both domain as well as UI.

Following is the list of various Actions can be called as action.


Hitting Web API action, I was getting this error: The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'. Check the solution...