Reference to workitem from presenter

Topics: CAB & Smart Client Software Factory
Jan 23, 2007 at 8:14 AM
I am currently working in a project where i try to apply SCSF. When i began the development i used pure CAB with no involvment with SCSF. I the hands-on-labs for CAB the controllers held references to their correpsponding workitems by using properties in the controllers:

Public Shadows ReadOnly Property WorkItem() As MyWorkItem
Return CType(MyBase.WorkItem, MyWorkItem)
End Get
End Property

The controller could access the workItem and call its methods in order to fulfill a Use case.

When i look att the BankBranchWorkbench example I dont see any presenters having references to their corresponding WorkItems. Actually it seems that the application is differently structured when using scsf instead of cab. It seems that the ModuleController does most of the job and other WorkItems is rarely used.

Does anyone have the same experiences or some comments regarding this?

Jan 24, 2007 at 9:09 PM
SCSF did change the way things worked a bit, but I think those changes were coming anyway (unless I'm mistaken) because the adopters of CAB were getting away from having presenters directly access WorkItems.

Where I work, we were in the same boat as you: we adopted CAB early, before the SCSF was fully baked, and so our basic structure looked different than the SCSF stuff that came out later. But one thing we got away from doing early was having presenters access WorkItems. That seemed like a code smell to me, for lack of a better way to describe it.

We found that when presenters could call methods on a WorkItem, that it blurred the lines of responsibility between those items. WorkItems then ended up doing some work that the presenter could do, because it was only a method call away.

To more clearly demarcate the boundaries of responsibility between WorkItems and presenters, we stopped giving our presenters references to the WorkItem. The responsibilities of each object cleared up. WorkItems became responsible for instantiating views and services, and providing services to presenters via the Dependency Injection framework. Presenters then became responsible for handling everything else: communication with the service facades, working with business objects, managing requests from UI elements and interacting with views.

Jan 24, 2007 at 9:11 PM
I have the same question, and have asked before, but no one has really given me an answer. I don't remember exactly what it related to before, as my mind is filled with 100 other things. I'm actually having an issue, and I'm going to post about it, and maybe that will shed some light on it for both of us.
Jan 24, 2007 at 9:13 PM
I just saw Chris' post, and I'm taking the same route so far. I use the workitems to add services and views and that's it. I try and stay away from doing anything else with WorkItems unless it's absolutely necessary to the function of the program.
Jan 25, 2007 at 8:03 AM
Thanks a lot for the response. I have actually begun to adopt the same pattern as you describe.

Nice to hear that I am not the only one facing these issues.
Jan 25, 2007 at 9:40 AM
Hello Chris,

You wrote :
> ... and providing services to presenters via the Dependency Injection framework ...

Can you give me an excample how the code looks like ? ( in the Modulecontroller and call the servive in the presenter of the view )
or any link / hint where i can see this.

Thanks in advance

Jan 25, 2007 at 10:03 PM

Here's an example:

In our ModuleController, it needs to add some Services so that Presenters can use them. In our ModuleController we create a method called AddServices, and call that on the overridden Run() method of the ModuleController. The code looks like this:

public override void Run()
// Create some WorkItems here and run them.

private void AddServices()
WorkItem.Service.AddNew<MyService, IMyService>();

So now the ModuleController has created a concrete version of the IMyService and added it to the highest level WorkItem in the module. Any subsequent WorkItems or Presenters should be able to grab it, like so:

public class MyPresenter : Presenter<IMyView>
private IMyService _myService;

public MyPresenter(ServiceDependency IMyService myService)
_myService = myService;

Now your presenter has a reference to the IMyService and can use it throughout its methods.
Jan 26, 2007 at 2:00 AM
Thank you Chris,

I have added your sample code (after implementing :-) and words from the discusion above on a howto in cabpidia. see How Tos

please be so kind to have look over it.

Jan 26, 2007 at 5:54 PM
Hey, looks good lesta :-)