Silverlight Dynamic Module Discovery

Topics: Prism v4 - Silverlight 4
Jan 3, 2012 at 7:45 PM

Hi there, I've spent a day going through the examples and using the prism 4 templates and wondering if I'm on the right track and have a question on the .xaps and loading them in.

I and my coworkers have just started using Prism 4 (with MEF & MVVM) and one thing that we need to do is beable to load new modules applied to the server without recompiling the web side project. Essentially if we could do what WPF does with a directory search of XAP files for the project would be perfect; but from my understanding silverlight is sandboxed (even with evaluated permissions) and requires a service implementation.

Now I assume this is more MEF and the way todo this is building a custom ModuleCatalog that uses "Dynamic" (LazyLoading) Modules that get their ModuleInfo from a Service linked to a database (since silverlight is sandboxed and can't access a config file). So my question is what of the .Xap files? I have to reference every assembly's .Xap in my .Web project every time I add a new project (Module) to my solution, do those need to be stored in a database and loaded in or can I just store it locally and access them without a reference within the web? Or are these no longer needed to be referenced when we pass in the ModuleInfo to the ModuleCatalog; and if this is the case where does the .Xap files go?

Based on -
I'd want to use a DeploymentCatalog for Dynamic Modules

Based on -
Snippet of code where a List of Modules is loaded in; its unity but same concept.

Thank you for any help you can give me,

Jan 3, 2012 at 10:05 PM

So I feel dumb for not rereading the one chapter I skimmed has some of the answers. So I can put my Module's .Xap in a common folder that my shell has access to, and then use a service to return a ModuleInfo for a Module from my database. Now I'm head home for the day so I can't test publish so I'm going to just ask for any tips you can give me on this. I'd have todo the 1st bullet point below to effectively do this correct?

[Copied from Chapter 11: Prism]

To deploy a Silverlight application and the modules that are remotely loaded, the XAP files must be made accessible on the web server. There are several ways to accomplish this:

  • You can manually copy all the XAP files to a public folder on the web server.
  • You can include the Silverlight XAP files in a web project or website and publish from Microsoft Visual Studio. To do this with a Web Application project, the project needs to be part of the same solution as the Silverlight projects that create the XAP files. You then add the Silverlight projects to the Silverlight Applications tab in the web project settings, as shown in the following illustration. A copy of the XAP files from the included Silverlight projects will be placed in a \ClientBin subfolder of the published site. These files are synchronized in the web project each time you build.


Jan 4, 2012 at 5:14 PM
Edited Jan 4, 2012 at 5:15 PM


I'm glad you found the information you needed, thanks for sharing your findings with the rest of the community.

Based on my understanding, the approach that suits your scenario, as you mentioned, is to "manually copy all the XAP files to a public folder on the web server".

Also, you may consider, as mentioned in the documentation, that the hosting web page will need to refer to the shell application XAP file in its object tag source parameter.


Agustin Adami