This project is read-only.

Get static objects from downstream classes

Nov 15, 2007 at 6:07 PM
I am very new to CAB, please pardon my stupidity.

I am building a project which is a module in a CAB/SCSF application. not an Architect, so only working from my module.

I have a ModuleController Class and a Module Class in my project.
I have a class in the WorkItem folder called LBTWorkAItem which inherits from WorkItem

I belive you get all these by default when the whole app is setup.

I have some objects that need to be static. I want to add them to the WorkItem items collection and retrieve them from other classes in my project as I work along. I am assuming that once I add an object to the WorkItems collection,
I can get it anywhere I need it, make changes to it and the next guy downstream will see the changes I have made.

What is the best way to go abouty this ?

I do not have access to ApplicationShell,
in my MyWorkitem code, I basically add my modules mainform to the WorkItem and call Workspace.Show on the Workspace passed in to my method /Module

Please help
Nov 16, 2007 at 11:45 AM
You can
  • use WorkItem state
  • use WorkItem Items bag
  • create your own service

I would recommend creating a context service or something like that. This will allow you to keep your stuff in a well known place and you can just add the service to the workitem.

Matias
http://staff.southworks.net/blogs/matiaswoloski
Nov 16, 2007 at 1:33 PM
I put the object in the workItem 's item bag from my module controller. How do I access the WorkItems's Item collection from my views presenter.

I tried inheriting my view presenter from the infrastructure's Presenter<TIview> , but the workitems collection in the views presenter is null.. I must be missing a step
Nov 16, 2007 at 4:35 PM


I have some objects that need to be static. I want to add them to the WorkItem items collection and retrieve them from other classes in my project as I work along.

Please help


Just to clarify some terminology: Objects cannot be static. Classes can. A static class cannot be added to a WorkItem collection because it is not instantiated. A static class would be accessible from anywhere, so there wouldn't be a need to store or inject it anywhere.


put the object in the workItem 's item bag from my module controller. How do I access the WorkItems's Item collection from my views presenter.


Presenters (when inheriting from the base Presenter<T> class from Infrastructure) know about their parent WorkItem. They have a reference to it; a little bit of intellisense inspection would reveal:

this.WorkItem.Items....


Nov 16, 2007 at 9:51 PM
Thanks for the clarification ChristHolmes.


My presenter inherits from the base Presenter<T> . I am trying to find the hook-point wiring I need to do to access the presenter from my views.

PS: I added the presenter and views manually to the project, not via a wizard. the presenter is a .cs file I added to the project and it inherits from Presenter<ImyViewInterface> and the the View is a user control I added to the project. with the smartpart attribute. my project module was created without a presenter or view

I do not have the benefit of the wizards ground work.

Here's the steps i have done, all manually on my module(project) in the SCSF solution.
1. I added a usercontrol file
2. Added a .cs file that inherits from the base Presenter<ImyViewInterface> class - an empty interface
3. In the ModuleController override of Run(), i have added this a couple of services and collections classes to the workItem's item bag and services collection

I'm stuck at how to access the presenter from my views. I tried adding the presenter to my views via ServiceAttribute dependency injection, and it is not injected.

the presenter.workItem is null at runtime.

Nov 17, 2007 at 4:14 AM

Elbino wrote:
Thanks for the clarification ChristHolmes.


My presenter inherits from the base Presenter<T> . I am trying to find the hook-point wiring I need to do to access the presenter from my views.

PS: I added the presenter and views manually to the project, not via a wizard. the presenter is a .cs file I added to the project and it inherits from Presenter<ImyViewInterface> and the the View is a user control I added to the project. with the smartpart attribute. my project module was created without a presenter or view

I do not have the benefit of the wizards ground work.



That's ok. The MVP pattern doesn't require the wizard, it just requires a working knowledge of the way the parts interact. I'll explain further down :)


Here's the steps i have done, all manually on my module(project) in the SCSF solution.
1. I added a usercontrol file
2. Added a .cs file that inherits from the base Presenter<ImyViewInterface> class - an empty interface
3. In the ModuleController override of Run(), i have added this a couple of services and collections classes to the workItem's item bag and services collection

I'm stuck at how to access the presenter from my views. I tried adding the presenter to my views via ServiceAttribute dependency injection, and it is not injected.

the presenter.workItem is null at runtime.


You're just missing a few steps is all. Easily remedied:

Your UserControl needs to inherit from the IMyView interface. Declaration should look like this:

[SmartPart]
public class MyView : IMyView
{

Additionally, in the View, you need to inject a Presenter. If you were using the SCSF, the Wizard would generate this code in the view:

private MyViewPresenter _presenter = null;
 
[CreateNew]
public MessageBoxViewPresenter Presenter
{
        set
        {
                _presenter = value;
                _presenter.View = this;
        }
}

The CreateNew attribute tells the injection container to create a new instance of that class. So you should never have to new one up yourself. All you should have to do to create the view and presenter at the same time is this (in a WorkItem or in the ModuleController):

IMyView view = Smartparts.AddNew<MyView>("someIdentifierName");

By doing that, the Presenter will get created and injected with its parent WorkItem, as that is part of the case class. From that point forward you should be able to access any other services or objects if you have previously added them to the WorkItem's Items or Services collections.

If you need more help don't hesitate to ask, or email me.

-Chris




Nov 17, 2007 at 7:32 AM
Thanks a million Chris,

I 'll implement your advice on monday.

Really appreciate your help. I should/will eventually switch to using the wizard, but I'd really love to know how the CAB systems interact, so I'll understand the code generated by the wizards.

regards.
Elbino