Sharing views...

Topics: CAB & Smart Client Software Factory
Apr 10, 2007 at 3:43 PM
Hi,

Does anyone have any idea what the best way is to share and use views from within different modules without having to duplicate code?

We have a project where we need to utilise a set number of generic views as part of a workflow. In thoery, it should be possible to call/show views from within different modules. The solution that we have at the moment uses a shared service which raises an event into the module that owns the shared views. The problem is that this way of doing things isn't very clean. Also, the workitem containing the shared view is not the same as the workitem responsible for the current workflow.

Thanks in advance,
Chris
Apr 10, 2007 at 4:47 PM
Edited Apr 10, 2007 at 6:48 PM
Implment a CAB service with methods as below. Use these methods anywhere in CAB modules as you needed. It will be more and more clean as it follows CAB's loosely coupled architecure

public class SmartPartCatalog : ISmartPartCatalog
{
private Dictionary<string, object> smartParts = new Dictionary<string, object>(); //Catalog of Parts
public CreatePart(string partName, Type partType); //If you know how to implement attributes, you can specify part name as a attribute in the design time, then no need of Type parameter since you can use reflection to get the type
public ShowPart(string partName, string workspaceName);
public HidePart(string partName);
public NotifyParts(string partNames);
public InitializePart(string partName);
public GetAllParts();
public object GetPart(string partName);
public string[] GetAllPartNames();
public WrapPart(string partName);
public UnwrapPart(string partName);
public GetWorkItem(string partName);
public SetWorkItem(string partName);
public ExecuteAction(string partName, string actionName);
public ExecuteCommand(string partName, string commandName);
}

Regards,
Venkat Nataraj
Sep 21, 2008 at 7:02 AM
@Chris,

Hi Chris,

Were you successful in apply the proposed solution? I'm new to this SCSF CAB business and I can't work out how to share views between modules. Did you use a service to add the shared views to a Dictionary? Any sample code?

@Anyone,

Any pointers for a newbee on how to do this please

Thanks
Delordson
Sep 22, 2008 at 5:55 PM
Edited Sep 22, 2008 at 5:57 PM

Hi,

 

Perhaps, you find these threads useful:

·         CAB - Open a View from another view that exists in another or in the same module

·         Sharing view between modules

 

If you are new to SCSF, you may be interested in having a look at the Getting Started section of the SCSF KB.

 

Ignacio Baumann Fonay

http://blogs.southworks.net/ibaumann/

Sep 27, 2008 at 10:10 AM
Hi Ignacio,

Thanks for the pointers. Very useful read.

I like the idea of keeping the view in a business module and placing it's interface in a shared module (Infrastructure.Interface for instance) but I can't seem to work out the correct way of doing this.
So...
  • I have MyModule1 in which I place MyView1 which implements IMyView1
  • I place IMyView1 in Infrastructure.Interface
  • To add MyView1 to a workitem in MyModule1 I do something like WorkItem.SmartParts.AddNew<MyView1>();
  • But how to I add MyView1 to a workitem in MyModule2 if all I have access to is the interface?

Sorry if this is so obvious I've still got a lot of reading to do.

Thanks for your help.
Delordson

Sep 29, 2008 at 4:47 PM

Hi,

 

You need to consider the use of that view. For example:

·         If you just need to display MyView1 (contained in MyModule1) after some operation/event (i.e.: a button click) has been executed in MyModule2, you should only notify MyModule1 to show MyView1 using any of the loosely coupled communication mechanisms (i.e.: Event Broker or Commands). In this way the view will be always created from MyModule1.

·         If you prefer to create MyView1 from both MyModule1 and MyModule2, you could consider placing the view in a common project.

 

Please, let me know if this helps, or send more information on your scenario.

 

Ignacio Baumann Fonay

http://blogs.southworks.net/ibaumann/

Sep 30, 2008 at 5:55 AM
Hi,

That's exactly what I needed. Some of my views are 'owned' by specific modules and need to be shown by those modules in response to events. Others are created by multiple modules so I'll move those to a common project.

Thanks for your help.

Delordson