I Unit of Work Pattern

KISS -Keep it simple stupid .A software principal to be followed in this blog post ..

Unit of Work is the concept related to the effective implementation of the Repository Pattern

A Repository Pattern can be implemented in Following ways:

One repository per entity (non-generic) : This type of implementation involves the use of one repository class for each entity. For example, if you have two entities Order and Customer, each entity will have its own repository.
Generic repository : A generic repository is the one that can be used for all the entities, in other words it can be either used for Order or Customer or any other entity.

We are interested the latter one.

For this you need to use EF 6.1.3 code first approach,ASP.net MVC 4/5 ,Simple Injector for DI and Class library ..

Two question i like to ask myself why DI and Why class library…That’s something can not be expressed in one blog post .But to give you a hint DI is the implementation of
SOLID design principal and class library is the way of separating different layer and give you ability to unit test and other maintainability ..

Lets jump to primitive.First Create a project with no class library and then separate it to one.I like the way to understand the basic first and then go for implementation .

Create a project named IUnitOfWorkWith3Layer

Go to package manager console
–EntityFramework 6.1.3
Install-Package EntityFramework
–Simple injector
Install-Package SimpleInjector -Version 3.1.5
Install-Package SimpleInjector.Integration.Web.Mvc -Version 3.1.5

or you can do it by Right click on References->Manage Nuget Packages and this following dependencies .

Note:Version is most important .Some time wrong version may not work with current ASP.NET mvc project .Better way to check this is to implement it separately to different project then implement it as whole

I unit of Work link

Leave a Reply

Your email address will not be published. Required fields are marked *