Silverlight Prism Module Not Ready

允我心安 提交于 2020-01-06 06:49:33

问题


I'm building a Silverlight 4.0 application with Prism (a.k.a. Composite Application Guidance). I have two modules, both defined in my ModuleCatalog.xaml as WhenAvailable. My Application_OnStart instantiates my Bootstrapper and invokes it's Run() method. Well after my application is started and up and running (in fact, the user has to click a button in the UI), I then attempt to load the modules:

foreach (ModuleInfo mi in moduleCatalog.Modules)
    ...
    Type moduleType = Type.GetType(mi.ModuleType); // moduleType ends up null!

Sometimes, moduleType ends up null. I've verified that when I encounter the null, the ModuleInfo's State is LoadingTypes not ReadyForInitialization. I assume this means it's still downloading the separate *.xap files for my modules and bringing their types into the application domain.

So what can I do? I'd happily block if I knew there was some event I could listen to to know they're finally all loaded.


回答1:


If you are going to use Prism, you should not bypass it and create your modules yourself. That is not the way Prism is supposed to work. Prism does not provide an event for load completion as that is not something you should need to do.

Simple case:

If you define a module catalogue then all those modules will be loaded progressively, so no need to load any manually in that simple case. You can create a start-up module in your root Silverlight app with a few module dependencies and that will be enough to get the first page visible while to rest of the app loads.

More info needed:

I can't tell what you are actually trying to accomplish from the above snippet, so more information would help, but you should be using Unity to resolve interfaces and never Type.GetType() directly. Your generally should not need to resolve a module itself and there are also methods for triggering load-on-demand loading in Prism (don't have them handy at the moment... will update this).

Thanks:

Your have accidentally provided a clue to the answer to another question I asked in Stack Overflow so thanks for that.



来源:https://stackoverflow.com/questions/3001228/silverlight-prism-module-not-ready

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!