Skip to main content


Showing posts from February, 2018

Design Pattern: Unit of Work

The Unit of Work pattern defines an approach to create logical transactions within a system that might otherwise not be transaction based. It commonly is used in conjunction with the Repository Design Pattern.

I have previously used the Unit of Work pattern only in relation to database operations, but it could be used for file access, other sources, or multiple types together; the key is that all work gets completed as if it were one action.
Reasons you would want to use the Unit or Work patternAllows for smaller components that do not need coordination logicMore efficient by reducing duplicated or unneeded work, only the final result is storedEnsures working with up-to-date entitiesIf one piece fails, all fail, guaranteeing data in a good state How do you implement Unit of Work? In my opinion, one of the best ways to use the Unit of Work pattern would be for your Unit of Work to be created as soon as a request comes into your system and to be completed right before you return a respo…