使用 DirectoryCatalog 时动态更改部件 (DLL)
使用 MEF
,在将新插件(包含 parts
的 DLLs
)添加到插件文件夹后,调用 DirectoryCatalog
上的刷新将更新容器(如果允许重组)并且新添加的插件变得可访问。
我的问题是,如果我们需要动态替换DLL
(part
)怎么办?
我尝试了此操作,但所有加载的部件
都被MEF
锁定(写保护)并且无法替换。
Using MEF
, after adding new plugins (DLLs
containing parts
) to plugins folder, calling a refresh on DirectoryCatalog
would update container (if recomposition is allowed) and new added plugins become accessible.
My question is what if we need to replace a DLL
(part
) dynamically ?
I tried this but all loaded parts
are locked (write-protected) by MEF
and cannot be replaced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.NET 锁定了您的 DLL。您无法从 AppDomain 卸载程序集,并且在加载它们时通常会有一个锁。您可以为 AppDomain 启用卷影复制,以便删除 DLL。它们仍然会被加载,但当您调用“刷新”并将它们从目录中删除时,DirectoryCatalog 会发现它们已经消失。
It's .NET that has a lock on your DLLs. You can't unload assemblies from an AppDomain, and while they are loaded there will normally be a lock. You can enable shadow copying for the AppDomain to let you delete the DLLs. They would still be loaded but the DirectoryCatalog would see they were gone when you called Refresh and remove them from the catalog.