1
votes

I have created a silverlight application with PRISM and MEF. Is there a way to populate the modules catalog through some web service or database call? The example shown in the PRISM documentation gets the module information through XAP file which is included in the Shell project. In my case i need to get this list from some service. I read some articles which suggested to create a custom ModuleCatalog which implements IModuleCatalog.

I am not able to find any example or code snippet on how to proceed. Any suggestions on how to accomplish this?

Thanks, Deepak

1

1 Answers

1
votes

Got the solution for this requirement. Inorder to do load the OnDemand Module in runtime, the Module Info object has to be added into the catalog

            ModuleInfo moduleInfo = new ModuleInfo();
            moduleInfo.ModuleName = item.Name;
            moduleInfo.ModuleType = item.Type;
            moduleInfo.Ref = item.Reference;
            ModuleCatalog.AddModule(moduleInfo);

The item shown in the above code is populate using a webservice call, which hits the database and gets the name, type and reference (example.xap).

This successfully adds the module catalog, the module catalog can be referenced in any ViewModel by just importing that property like below

    [Import(AllowRecomposition = false)]
    public IModuleManager ModuleManager;

    [Import(AllowRecomposition = false)]
    public IModuleCatalog ModuleCatalog;

Inorder to Load the module during a button click or any event just call the ModuleManager.LoadModule(YourModuleName); and thats it, it will be available for use.