- Motivation
- Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
- Summary
This pattern keeps track of everything that happens during a business transaction that affects the database. At the conclusion of the transaction, it determines how to update the database to conform to the changes. - This is one of the most common design patterns in enterprise software development is the Unit of Work.
- It maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.
- The Unit of Work pattern isn't necessarily something that you will explicitly build yourself, but the pattern shows up in almost every persistence tool.
- The ITransaction interface in NHibernate, the DataContext class in LINQ to SQL, and the ObjectContext class in the Entity Framework are all examples of a Unit of Work. For that matter, the venerable DataSet can be used as a Unit of Work.
- When to Use
- Usually pattern is implemented by data access framework such as entity frameworks.
- Alternatively it can be explicitly be used when several transaction are modifying business object and you need to track them until changes are pushed to database
- Implementation
- In most of the cases this pattern is implemented by ORM frameworks like Entity Framework
- Related Patterns
- Repository Pattern
- Related Technologies
- Entity Framework : DBContext object of Entity Framework implement this pattern out of the box
- Specific Considerations
- Unit of Work Vs Repository Pattern
- Usually Unity of Work is implemented by data access framework like entity framework and repositories usually consume them.
- In other words repositories are used to create business objects and Unit of Work is used to track the changes made by business transactions to the business objects. Read More ...
- References
- Overview Tutorials
- Further References
- MSDN:The Unit Of Work Pattern And Persistence Ignorance
- Implementing the Repository and Unit of Work Patterns in an ASP.NET MVC Application
|
|