Thursday, January 8, 2009

Smart Clients and System.Transaction - Introduction

System.Transactions! I've been excited about it ever since I heard about it the first time, and generally I have not been disappointed. The ability to write data to several sources at once and easily handle the "transactional atomicity stuff" with just a couple lines of code: easy, nice, elegant.

If you have read any of the rhetoric coming out from Microsoft concerning this functionality (here in the documentation of TransactionScope, for instance), you will have noticed the term Ambient Transaction popping up all over the place. It's an interesting term, and to me it communicates something akin to infrastructure (ambient = surrounding space = scaffolding that is easily reachable from anywhere ). I started envisioning using System.Transactions as an infrastructure component for use in smart clients. The whole point being to be able to coordinate the "transactional needs" of loosely coupled components on the client.

To make it a bit clearer: I'm operating in the Smart Client, Composite Application area. I have several visual components that know nothing of each other or the environment that they are running in with the exception of a few interfaces describing the shell. Some of these components change data, and these changes must be persisted on the server. Often several unrelated components change data at the same time in what the user perceives as an atomic transaction (all or nothing). I want these changes to be gathered and assembled into a single change request which is sent to the server for replay. Needless to say, I also want the ability to rollback at any time.


Why not let System.Transactions become the backbone of this "change gathering framework"?
  • It's already installed on every machine running .net
  • It's easy to communicate how to hook into the infrastructure (just implement IEnlistementNorification !) to others.
  • Well tested, well documented, well known
  • And, indeed, ambient

So what we're talking about is using System.Transactions for something that I think it is incidentally well suited for, but which it was not primarily designed for.

And now I have built it. Overall it has been a success and a pleasant experience. However there have been some surprises and hurdles to overcome. My plan is to document my voyage in a series of posts (about 4, I guess) on this blog.

Stay tuned!

No comments:

Post a Comment