Skip to main content

Posts

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 pattern Allows for smaller components that do not need coordination logic More efficient by reducing duplicated or unneeded work, only the final result is stored Ensures working with up-to-date entities If 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 yo...