Design Pattern - Unit of Work

0

Category :

Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
http://martinfowler.com/eaaCatalog/unitOfWork.html

Basically unit of work is transaction management. Within one transaction, we may pull data from database, make some changes, add new record, etc.

There are some important notes about unit of work and web application:
1. Unit of work should be unique for each request, i.e. unit of work cannot share between requests.
2. Unit of work should be share within one request, i.e. if you use unit of work from your controller and other places, that unit of work object should be the same if it is within one request.

Dependency Injection comes to rescue to make sure the above requirements are met. Dependency Injection provides life time management and resolving the dependencies. For our case, unit of work object's life time must be per request.

http://sdesmedt.wordpress.com/2009/02/18/unit-of-work-pattern/



my thanks to: http://jittuu.com/2012/2/9/UnitOfWork-pattern-and-asp.net-mvc/

0 comments:

Post a Comment