Loading modules in separate XAP files

A quick description of the problem. This section describes how PRISM enables loading XAP files.

What is a XAP file?

These files are generated for each Silverlight application project. A .XAP file is a ZIP archive containing all the .NET assemblies for an application. This file is used to deploy Silverlight application. However, it is also used to distribute dynamic modules.

Loading PRISM in XAP files

PRISM module catalogs allow loading modules from external XAP files. For example:

ModuleCatalog myCatalog = new Microsoft.Practices.Prism.Modularity.ModuleCatalog();

myCatalog.AddModule(
         new ModuleInfo("ExtraModule1", 
                        "MyExtraModule1.ExtraModule1, MyExtraModule1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
         {
              Ref = "MyExtraModule1.xap"
         });

In this case the Ref property (https://docs.microsoft.com/en-us/previous-versions/msp-n-p/gg431319(v=pandp.38)) specifies the name of a file in the ClientBin folder of the Web server. Notice also that the instance of ModuleInfo is created with an assembly qualifed class name(https://docs.microsoft.com/en-us/dotnet/standard/assembly/find-fully-qualified-name) that includes the name of the assembly to be located inside the XAP file.

When configuring a catalog this way the Silverlight runtime performs a request for the requested XAP file:

Network traffic when loading a Silverlight Application

Notice that in this image the main application XAP file (BasicPrismModulesExperiment.xap) is downloaded first. Other module XAP files are downloaded later (MyExtraModule1.xap and MyExtraModule2.xap).

Once these files are downloaded the Initialize method is called for each module class. This initializes method performs a module registration action for example:

  • Registering new services to a DI container

  • Registering regions

  • Any other custom code actions

Last updated

Was this helpful?