Up Extend code samples
DevForce 2010 Resource Center » Code samples » Extend code samples » Code sample: Silverlight modularity with Prism (Silverlight)

Code sample: Silverlight modularity with Prism (Silverlight)

Last modified on October 28, 2011 11:20

This code sample demonstrates downloading and launching Silverlight modules dynamically.


Problem

A large Silverlight application can take seconds or minutes to download and start  ... even though the user only needs to see one screen. 

Solution

Users respond favorably to applications that start quickly. 

Why make the user wait? She may not get around to some of the features until later in the session. Other features she may not be authorized to use at all. 

The application can launch quickly when the initial download package - called a XAP - is small. The other features can be downloaded in the background, perhaps on demand and only for authorized users. The secret is modularity. Break down your application into a collection of modules, each in their own XAP package.

DevForce/Prism modularity quickstart

The Microsoft Patterns and Practices team released a Modularity-with-MEF Quickstart as part of Prism v.4. The Quickstart shows you how to write modular applications and deploy them in separate XAP files. 

This code sample is a version of that Quickstart, modified to demonstrate modularity with DevForce.

We added DevForce module registration to three of the original modules, 'A', 'C', and 'F'.

Each module has been extended with DevForce entity models that are defined in the web application project, ModularityWithMef.Silverlight.Web. These models are generated from three Entity Data Models (EDMs) as follows:

  • ModelA.edmx: an EDM with Customers for Module A
  • ModelC.edmx: an EDM with Employees for Module C
  • ModelF.edmx: an EDM with Orders for Module F

These particular modules were chosen because they exhibit a variety of module loading options in the Quickstart:

  • Module A: loads when the app starts; it runs immediately.
  • Module C: loads when the app starts but runs only when the user pushes the 'C' button.
  • Module F: both loads and runs on-demand, when the user pushes the 'F' button. Module 'F'  depends upon on-demand loading of Module 'E'.

Modularity in action

Here is the initial screen after Module 'A' has loaded and retrieved Customers from the NorthwindIB tutorial database.

ModularitySample1.png

Notice that the revised module adds a DevForce entity retrieval message to the scrolling log.

Here is the log after on-demand loading of Module 'F':

ModularitySample2.png

Source code

Download the sample zip file and give it a try. You won't need to download Prism; the referenced Prism libraries are included in the zip. 

The application code is in the ModularityWithMefSL directory. DevForceReadme.txt files at this level and in each of the modified project directories identify and explain the DevForce changes. Comments in the code explain how it works.

The original Prism source code can also be downloaded.

Created by DevForce on March 25, 2011 11:55

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2015 IdeaBlade