Commands across modules

Topics: CAB & Smart Client Software Factory
May 3, 2006 at 6:44 AM
originally posted by: Jochen_Dedte


I'm having some difficulties to create and subscribe to commands across different modules.

Suppose I have module A in which I would like to register to a command of module B. Since I don't want any dependencies between the modules (except for the command name), I cannot reference module B in module A.

I thus cannot write the following code in module A

workItemB.Commands"commandName".AddInvoker(menuToolA, "Click");

The RootWorkItem also is useless since it belongs to the shell project and has no references to module A nor B.

I guess there's a very elegant way to solve this, but I cannot find this.

Could anyone clarify?

Thanks a lot!

Jochen Zeischka
May 3, 2006 at 8:04 AM
originally posted by: ChrisHolmes

What you could do (and I doubt this is the most elegent solution or the right way to do it) is to create a UIElementManager service that you can register with the RootWorkItem. This service would be in charge of doing nothing more than maintaining an IDictionary<string,menuItem> list of menu Items. Each menu item would need a unique string name in the dictionary list, but if you use a URI that isn't difficult (ex: "WorkItemA/SaveMenuItem" & "WorkItemB/SaveMenuItem").

Via the service you should be able to get the reference to the actual menuItem and tie that Command to it.
May 4, 2006 at 12:19 AM
originally posted by: Jochen_Dedte

I've worked my way around it using a common interface for the root WorkItem. This allows me to reference it anywhere.

Commands are used within modules and where cross-module communication is needed, the common interface is used. The root WorkItem itself uses global event publication to pass the requested command to the unknown target module.

I guess it's not quite how it's supposed to be done, but it works.

If there are better ideas out there concerning cross-module command registration, please let me know! I have the feeling that I am not fully exploiting UIElements and UIElementAdapters...