Posts

Showing posts from March, 2017

Repository and Unit of Work Patterns in an ASP.NET MVC Application

Image
Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application The repository and unit of work patterns are intended to create an abstraction layer between the data access layer and the business logic layer of an application. Implementing these patterns can help insulate your application from changes in the data store and can facilitate automated unit testing or test-driven development (TDD). In this tutorial you'll implement a repository class for each entity type. For the  Employee  entity type you'll create a repository interface and a repository class. When you instantiate the repository in your controller, you'll use the interface so that the controller will accept a reference to any object that implements the repository interface. When the controller runs under a web server, it receives a repository that works with the Entity Framework . When the controller runs under a unit test class, it receives a repository that works with data stored ...
Dispose method and Finalize method Class instances often encapsulate control over resources that are not managed by the runtime, such as window handles (HWND), database connections, and so on. Therefore, you should provide both an explicit and an implicit way to free those resources. Provide implicit control by implementing the protected   Finalize   on an object (destructor syntax in C# and C++). The garbage collector calls this method at some point after there are no longer any valid references to the object. In some cases, you might want to provide programmers using an object with the ability to explicitly release these external resources before the garbage collector frees the object. If an external resource is scarce or expensive, better performance can be achieved if the programmer explicitly releases resources when they are no longer being used. To provide explicit control, implement the   Dispose   provided by the   IDisposable . The consu...