Dynamic/On Demand loading of XAP dependancies using MEF?
I have been reading the article: http://www.codeproject.com/KB/silverlight/MEFDynamicLoading.aspx which describes how it is possible to have XAPs dynamically downloaded using MEF. It states t开发者_高级运维hat shared libraries should be referenced with copy local set to false. This works great if the 'host' xap has them also referenced with copy local set to true, however this is not the scenario I want to support. My application has what amounts to a tree structure of sorts. With items on the same level often (but not always) sharing large (Maybe as much as 1MB) dependancies. What I want is to load these dependancies only if/when they are needed. The obvious thing would be just to have copy local set to true throughout, but what I wish to ensure is that dependancies are only downloaded once. Even if the user then navigates to other areas of the application that require the dependancies.
As a final couple of points: I want to be able to load these dependancies ahead of time. i.e. when I know that the application is not doing anything else worthwhile. I will also be making use of the offline catalogue described in http://www.wintellect.com/CS/blogs/jlikness/archive/2010/05/25/silverlight-out-of-browser-dynamic-modules-in-offline-mode.aspx to ensure that it works as expected out of browser.
Honestly the only way to really do this if you aren't willing to have the local references in the main XAP is to crack open the manifest and parse it yourself and not use the deployment catalog. You'll need to basically use the methods I exposed in the offline catalog, and keep a dictionary of references already loaded. Then you can copy local for everything, and the code will check and only load in the referenced assembly if it hasn't been loaded before.
精彩评论