Kiwi Ingenuity

Thoughts from another perspective

WCSF - Sharing the Controller

While working on a Web Client Software Factory solution, I found myself in a situation where I wanted several presenters to share the same controller.

How this came about was that I had a page that deployed several User Controls that had their own presenters.  These same User Controls needed to communicate with one another, so sharing the same controller, was the solution I needed to deploy.

Mats Lycken had obviously needed to solve the same problem some months earlier and has posted a solution that certainly did the job for me.  He has published a [CreateShared] attribute which can be deployed to replace [CreateNew].

The [CreateShared] attribute enabled me to share the same Controller.  Mats has provided us with library which needs to be included in our project as well as a working example to see how to use the new attribute.

Further documentation can also be found here.  This link refers to a solution that Mats posted in the WCSF Contrib.  I also tried the Contrib solution and have to confess it left me rather confused?  My recommendation is to follow the first link above.

Thank-you Mats for a fine effort!

Comments (2) -

  • nagendra

    8/17/2009 11:41:13 AM | Reply


    I have a question ,can you please let me know how to access the Controls that are present in View from the presenter in WCSF.
    in WCSF every event will call a method in presenter, for eample i i need to display a label can i assign the label value feom the presenter itself, if so how to access the label in presenter.


  • Admin

    8/17/2009 9:58:09 PM | Reply


    The presenter can assign anything in the View.  In fact that's what it's there for.  Lets take your label example....and lets take the simplist answer you could do...
    (1) When you created the label in the View it's visability is set to private.  You can easily change this to public using the modifiers property in the designer.
    (2) Add an entry in your view interface that exposes thes public member i.e. string mylabel {set;)
    (3) Now in your presenter set the label value.  i.e. mylabel = "new value";

    However these answers are never that simple, because what you might well be asking (and I'm guessing here) is that you want to change the label value depending on some event or changeing some kind of status.
    You would most probably then consider instead adding a function to your view
    public viewStatus Status
    mystatus = value;
    if (value = something)
    mylabel.text = "new text value";
    In the interface would expose the status function and in the Presenter you would say View.Status = whatever.

    Sorry for the shorthand, but hopefully the above makes sense?