WPF Prism - 管理应用程序中的模块 [英] WPF Prism - Manage Modules In Application

查看:85
本文介绍了WPF Prism - 管理应用程序中的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WPF 中使用 Prism,我希望允许用户从存储库中选择他们想要使用的模块.每个模块本质上都是一个附加组件,选择要使用的模块只需将其移动到 DLL 的模块"文件夹中即可加载.

Using Prism with WPF, I want to allow users to select from a repository which modules they'd like to use. Each module is essentially an add-on, and selecting a module to use would just move it into their 'Modules' folder of DLL to load.

但是,在应用程序运行时尝试移动 DLL 时会引发错误,因为此时 DLL 正在使用中.您如何解决这个问题并允许用户随意添加/删除模块?

But, in trying to move DLLs around when the application is running, an error is thrown because the DLLs are in use at that moment. How can you get around this and allow users to Add/Remove modules at will?

推荐答案

一旦将程序集加载到 AppDomain 中,它不会(无法)卸载,直到 AppDomain> 被拆除了....我想那是你的问题.

Once an assembly is loaded into an AppDomain, it does not (cannot) get unloaded until the AppDomain is torn down....I guess that is your problem.

如果您在网上查看,有一些技术可以解决这个问题.....

There's some techniques to get around that if you look on the net.....

创建一个额外的AppDomain,然后你可以将你的程序集加载到......当你完成后,你只需调用Unload来关闭AppDomain代码>,这将释放程序集.

Create an additional AppDomain which you can then load your assembly into....when you are finished you just call Unload to shutdown the AppDomain and this will release the assembly.

但是,您希望从其他 AppDomains 访问的类型必须从 MarshalByRefObject 派生,以便您的对象可以远程....并且来自其他 AppDomains 的调用可以被编组.

However the types you want to be accessible from the other AppDomains have to derive from MarshalByRefObject so that your object is remoteable....and calls from other AppDomains can be marshalled across.

这里有一个非常有趣的技术......它首先将程序集加载到 MemoryStream 中,然后它让 .NET 从 MemoryStream 加载程序集......这意味着磁盘上的文件"没有被锁定.

A very interesting technique here....it loads the assembly into a MemoryStream first, then it gets .NET to load the Assembly from the MemoryStream...that means the "file" on disk, isn't locked.

如何在没有使用 AppDomains?

这篇关于WPF Prism - 管理应用程序中的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆