This code sample demonstrates downloading and launching Silverlight modules dynamically.
A large Silverlight application can take seconds or minutes to download and start ... even though the user only needs to see one screen.
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.
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:
These particular modules were chosen because they exhibit a variety of module loading options in the Quickstart:
Here is the initial screen after Module 'A' has loaded and retrieved Customers from the NorthwindIB tutorial database.
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':
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.