Common view

Topics: Prism v4 - Silverlight 4
May 9, 2012 at 5:20 AM
Edited May 9, 2012 at 5:21 AM

I am new to prism and the patterns it uses. I have 3 modules; Sales, Purchasing and Common. Sales has a class called Customer and Purchasing has a class called Vendor. In the Common module I made a view called ContactEditor. Both Customer and Vendor use Contact. When I make my customer editor I want to embed the contact view in it, as well as in the vendor editor. I could just make references from the sales and purchasing modules directly to the common module, but I feel that this may be in violation of the loosly coupled principal. However, it feels silly to drop the common module and code the contact editor in both sales and purchasing. Is there an accepted practice for sharing a piece of UI?



(Prism 4.1, with silverlight 5)

May 9, 2012 at 7:23 PM

Hi Phylum,

Generally when building composite applications the approach followed is having a common shell composed of UI components contributed from various modules that interact in a loosely coupled way. Hence your modules usually shouldn't have references between each other.

To achieve this the Prism library provide the Region functionality that allows placing dynamic content contained in modules in predefined placeholders in a UI container.

Hence you could keep you modules' loosely coupled by defining regions to specify where your views will appear, as this regions will act as placeholders for one or more views that will be displayed at run time. Then your modules can locate and add content to regions in the layout without knowing how and where the region is displayed.

You could find more information about regions, and how to add content to this regions from your modules in the following chapter of the Prism documentation:

Also, take into account that if one of your modules depends on components and services provided by other module, Prism also supports the ability to register dependencies between modules so that they are loaded and initialized in the right order. During this initialization, the module can retrieve references to the additional components and services it requires, and/or register any components and services that it contains in order to make them available to other modules.

More information about this can be found in the following section of documentation:

I hope you find this useful,

Agustin Adami