Getting Work Items from the Store

 There’re few things I want to share about the WorkItemStore::GetWorkItem() method.First, it may sound clear for everybody, but:

WorkItem a = wis.GetWorkItem(10);

WorkItem b = wis.GetWorkItem(10);

The instance a and b won’t be the same, you’ll have two separate objects for the same Work Item!

WorkItem instances could have been considered as singleton, with only one instance of a given WorkItem in the store. Would that made sense to you?
Personally, yes, it would.

GetWorkItem() is slooooow, I mean it, really, on my WebService which tracks states changes to synchronize related work item, I found out that 90% of the time execution was in that call (believe me, there’re much more than that in this WebService).As I was getting many time the same ID, I quickly made a class that implement a Work Item cache, based on a List<> (I know it’s maybe not the fastest way to find a occurrence from a given key, but well…)On my WebService, it turns out I was six times faster with this implementation…If Work Item were considered as singleton, I think I wouldn’t have had this performance issue.

And one last thing: if you modify a, then b, then a.Save() and b.Save(), you’ll have a nice exception throwing at you on the second Save call, with the impossibility to conciliate both changes (easily at least)…Not very cool !