使用 MEF 动态/按需加载 XAP 依赖项?
我一直在读这篇文章: http://www.codeproject.com/KB/silverlight/MEFDynamicLoading.aspx 其中描述了如何使用 MEF 动态下载 XAP。它指出共享库应该在复制本地设置为 false 的情况下引用。 如果“主机”xap 也将它们引用为复制本地设置为 true,则效果很好,但这不是我想要支持的场景。 我的应用程序具有某种树结构。同一级别的项目经常(但并非总是)共享大量(可能多达 1MB)的依赖项。 我想要的是仅在需要时加载这些依赖项。显而易见的事情就是将 copy local 设置为 true ,但我希望确保依赖项仅下载一次。即使用户随后导航到需要依赖项的应用程序的其他区域。
最后几点: 我希望能够提前加载这些依赖项。即当我知道该应用程序没有做任何其他有价值的事情时。 我还将利用 http://www.wintellect.com/CS/blogs/jlikness/archive/2010/05/25/silverlight-out-of-browser-dynamic -modules-in-offline-mode.aspx 以确保它在浏览器外按预期工作。
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 that 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,如果您不愿意在主 XAP 中拥有本地引用,真正做到这一点的唯一方法是打开清单并自己解析它,而不是使用部署目录。您基本上需要使用我在离线目录中公开的方法,并保留已加载的引用字典。然后,您可以将所有内容复制到本地,代码将进行检查,并且仅在之前未加载过的情况下加载引用的程序集。
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.