Rich Newman

July 14, 2007

An Introduction to the Smart Client Software Factory and Composite Application Block: Part 2 WorkItems

Introduction

In part 1 of this article I introduced a simple example of how to use Microsoft’s Composite Application Block. To try to keep the example as simple as possible I only covered modules and shells.

There are two other core concepts that you need to understand to be able to use even the most basic functionality of the CAB. These are WorkItems, and dependency injection. This part of the article will discuss WorkItems, and part 3 will discuss dependency injection.

WorkItems – Basic Concepts

Microsoft’s documentation defines a WorkItem as ‘a run-time container of components that are collaborating to fulfill a use case’. In many ways the best way to think of them is as classes that contain collections of other classes that are logically grouped together. The name is a little strange: ‘work items’ in general tend to be individual tasks that need to be performed in, say, a workflow, or, in the .NET Framework, in a thread pool. The WorkItems in the CAB are broader than that.

In code terms WorkItems are just objects of type ‘WorkItem’ (a class in the Microsoft.Patterns.CompositeUI library). Each WorkItem has collection classes associated with it to allow it to ‘contain’ components. Three of these collection classes that are reasonably easy to understand are:

  1. The Items collection, which can contain almost anything since it’s a (special) collection of System.Objects
  2. The Services collection, which is a collection of CAB services.
  3. The WorkItems collection, which is a collection of other ‘child’ WorkItems.

However there are several other collections of CAB code objects on the WorkItem class. WorkItems also have state (used to track changes), and status (active/inactive).

Container Hierarchy and the Root WorkItem

There’s a second important aspect of WorkItems: they can be arranged into a hierarchy. This hierarchy typically starts with a root WorkItem that contains components (code objects) and other WorkItems, the other WorkItems again can contain components and other WorkItems, and so on.

This is particularly useful since we can construct the hierarchy across modules, even though the individual modules may not reference each other. We can then use the WorkItem hierarchy to use components in other modules.

I’ll show exactly how this works in a minute, but in our example from part 1 we could add a WorkItem class to each of our three projects. We could then instantiate one WorkItem object per project at runtime. The WorkItem object in the Shell program could be a root WorkItem. It could contain the other two WorkItems.

If we add a component from the Shell project to the root WorkItem we can access that from, say, the Red application’s WorkItem by simply using this.ParentWorkItem.Items[“ComponentName”].

One obvious difficulty with this approach is that we are then tightly-coupling our two modules together to some extent, which is what we were trying to avoid by not having direct dependencies between our modules. However, as we’ll see we can still release new versions of each module independently of the rest of the code.

WorkItems and the FormShellApplication

In part 1 of this article we saw that to start a CAB application we inherit from FormShellApplication<,>. We provide two types when we declare the new class to close the generic definition:

    public class Program : FormShellApplication<WorkItem, Form1>
    {

As we have seen the second of these (Form1) is the shell for the application and gets instantiated and shown at start up (when we do new Program().Run()). The WorkItem also gets instantiated at start up. This will be the root WorkItem for the application, sitting at the top of the hierarchy described above. It can be referred to in the Program class using the RootWorkItem property (this.RootWorkItem).

To be continued in part 3.

About these ads

10 Comments »

  1. Thanks for the Article…

    I went throught lot of articles on SCSF. But this one is very simple and easily understandable.

    Comment by Ilankuzhali — October 18, 2007 @ 11:15 pm

  2. I’ve read a lot of stuff on the CAB, but this is the best explaination of WorkItems and how they fit in. Thanks.

    Comment by John Smith — November 2, 2007 @ 2:25 pm

  3. where is the code for part 2 please?

    Thanks

    Comment by carleton — November 8, 2007 @ 10:47 pm

  4. The material and the examples provided enables a clear understanding of the concepts..

    Comment by kirthika — December 4, 2007 @ 9:58 am

  5. too gud, thanks a lot…

    Comment by surjit — February 14, 2008 @ 8:50 am

  6. this is helpful for starting

    Comment by samiksha — September 19, 2008 @ 7:08 am

  7. [...] This article is continued in part 2, where I explain WorkItems, and part 3 where I will explain dependency injection, and show how we can get the two forms in the Red and Blue projects in our example to be MDI children in the shell. [...]

    Pingback by An Introduction to the Smart Client Software Factory and Composite Application Block: Part 1 Modules and Shells « Rich Newman — April 26, 2010 @ 2:25 am

  8. thanks very much, your articles is very helpful. thanks

    Comment by Le Tuan Dũng — April 28, 2010 @ 2:08 pm

  9. Thank you, you saved me so much time !

    Comment by Alek Karpov — June 7, 2010 @ 1:24 am

  10. Hello just wanted to give you a quick heads up.
    The text in your content seem to be running off the screen in Chrome.
    I’m not sure if this is a format issue or something to do with internet browser compatibility but I thought I’d post to let you know.

    The design look great though! Hope you get the problem resolved soon.

    Many thanks

    Comment by Deloris — November 13, 2012 @ 5:23 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 80 other followers

%d bloggers like this: