Unit of Work Edmonton Code Camp Oct 2007 Presenter: Neil Bourgeois
Layered Architecture Presentation Domain Data Access Service
Transaction Script Anemic Domain Service Layer gets cluttered with business logic and Data Access Layer CRUD Difficult to keep Domain persistence ignorant Difficult to make transactional
Unit of Work Tracks everything done during a business transaction Figures out which CRUD actions need to be applied to persist changes Completes changes in a database transaction
Implications New objects need to be registered with UoW Objects loaded from database need to be registered with UoW Need to know when objects change Service Layer never calls Data Access layer directly
Repositories Abstraction of the database New and Existing objects are created through a repository Repository registers New and Existing objects with UoW Domain objects can use repositories to find other domain objects
Object State Per object change observer Possible States: New Clean Dirty Remove Persisting
Identity Map Keeps track of domain objects loaded through repositories Keeps track of object state
Workspace Transaction Per Session (HttpRequest) Thread Safe Contains Identity Map Manages persistence
Lets Code!