Unit Of Work Pattern

I’ve done some research on the Unit Of Work pattern and this post will show you what I’ve learned.

Definition

A short version of the official definition of the term “Unit Of Work” can be found on Martin Fowler’s website. A longer version can be found here.

Implementation
A small proof of concept type of implementation can be found at Code Insanity: The Unit of Work Pattern. He continuous in his post Implementing a persistence ignorant Unit of Work framework.

Looking around the internet for information you will often find remarks about the Unit Of Work pattern in conjunction with multiple threads. The article over at InfoQ named Confusing unit-of-work with threads gives a good overview on the caveats lurking there.

Now, how do we use this Unit Of Work?

Usage in ASP.NET applications

There is a great deal of concensus on how to apply the unit of work pattern in web applications in general and in ASP.NET in particular.

In general, in web applications the Unit Of Work per Request implementation is used. You can find a sample implementation in the article Using the unit of work-per-request pattern in ASP.NET MVC and using NHibernate in NHibernate Best Practices with ASP.NET
An alternative is the Unit Of Work per Conversation. The Transactions and Units of Work in Web-Applications article gives a good general introduction and the post What are the benefits of session-per-conversation? compares the two approaches.

Usage in Windows Foms applications

Windows Forms applications are a completely different beast. In a web application there is a natural boundary of a request. There is however no such thing in a winforms application. So finding guidance is difficult. The abone mentioned post Transactions and Units of Work in Web-Applications is a good start.

Conclusion

The Unit Of Work pattern is a basic pattern to streamline data access in applications. It provides a means to keep track of changes to your business objects and apply the changes as a single unit of work to your database,

I hope you found the links illumminating and if you have any yourself, please leave a comment.

Links
Definition:
P of EAA: Unit of Work
IS Architecture Pattern: Unit of Work

Implementation:
Code Insanity: The Unit of Work Pattern
Code Insanity: Implementing a persistence ignorant Unit of Work framework
InfoQ: Confusing unit-of-work with threads

General usage:
Transactions and Units of Work in Web-Applications

In ASP.NET:
Using the unit of work-per-request pattern in ASP.NET MVC
NHibernate Best Practices with ASP.NET, 1.2nd Ed.
Appling Unit Of Work pattern
ASP.NET MVC, DataContext and The Unit of Work Pattern

Advertisements

The Practical Traveller

The holidays are back again, and everyone is preparing for their holiday trip. Our European roads are stuffed with cars filled with people and their luggage. They all share a common goal:

“Get there co-travellers as fast and comfortable possible to their destination”

There are of course different ways for drivers to prepare for the trip.
Continue reading

Can you write an object oriented program?

At TheServerSide.COM an interesting article was published:  Java Succumbing to .NET in my Organization Alltough to my feeling, the article really is about tooling, some commentators manage to bend the discussion and suggest that .Net programmers are worse object oriented programmers because of the wizards made available by Microsoft in Visual Studio. Personally I do not believe that to be right, but I suggest to have that discussion over there.

What interests me is how those great object oriented programmers got their skills. What books did they read, what sites do they visit? Anyway, here are some sources that helped me, but I do not consider myself being "Great":

Books:

Articles:

websites:

Of course, reading a lot of articles about programming itself, downloading code and analyzing it wil get you further too, but above are links to books, articles and websites from which I acquired a deeper understanding of the subject. Reading code alone doesn't do the trick, by reading the above and then looking at code you will start to learn why things are done the way they are, or how things have been done but could have been done better.

Of course, you might have a list of your own, so put it in the comments.