Module UI Injection

Topics: CAB & Smart Client Software Factory
Jun 13, 2006 at 12:25 PM
originally posted by: Bradley1976

I am exploring the CAB for possible use as a framework for our new .NET application. This is a probably a pretty basic question, so if someone can steer me in the right direction that would be greatly appreciated.

From my understanding of the CAB it is possible to "inject" dependency so that Module A can be dependant on Module B in specific ways. It is also the case that your main application does not have to be aware of Module A or Module B when it is first created and compiled. Modules A and B can be dynamically loaded when the main application starts and reads its catalog and the main application needs to have no previous knowledge of any of its modules. Please correct me if my understanding so far is incorrect.

My primary question is this: Can the UI of the main application be altered by these dynamically loaded modules? In other words, can Module A (that the main application had now previous knowledge of when created and compiled) inject it's own UI elements into the main application? If so, can someone please direct me to the appropriate documentation of this feature?

Jun 13, 2006 at 2:39 PM
originally posted by: ChrisHolmes

Yes, modules can alter the appearance of the Shell by doing one of several things:

(1) Adding menuItem or toolStripItem elements to MenuStrips and ToolStrips.

(2) Showing their own views in Workspaces that the Shell houses.

For instance, a common workspace to utilize is the DeckWorkspace, which acts like a Deck of cards. You can have a DeckworkSpace on the Shell form. It is just an empty DeckWorkspace at this point in time and the Shell knows nothing about any modules that will access it. WorkItems (containers stored in a Module, which is really just a .dll) can create views and show them in the Shell's DeckWorkspace.

Utilizing the Workspaces allows your Shell application to be completely ignorant of any modules that it may load.
Jun 13, 2006 at 10:22 PM
originally posted by: KayLerch

The Main-Application shares its UI-Elements like a menustrip or a toolstrip with the modules. This is done via UIExtensionSites, which are references to the UIElements. First of all, these UIExtensionSites must be stored in the Shell's rootWorkItem (it is a kind of object-container)

RootWorkItem.UIExtensionSites.RegisterSite("MyMainMenu", Shell.MainMenuStrip);

To access the RootWorkItem in a module without binding it to the Shell, you have to use "dependency injection".

public CommonInit(ServiceDependency WorkItem rootWorkItem)
_refrootWorkItem = rootWorkItem;

There is nothing to comprehend (so far). All the work is done by the CAB's object builder.
Now you've got the reference to the WorkItem of the Shell -> and the reference to the UIElements of it.

ToolStripMenuItem menuItem = new ToolStripMenuItem("File");