gpt4 book ai didi

c# - MEF导入解析

转载 作者:太空狗 更新时间:2023-10-29 23:09:11 24 4
gpt4 key购买 nike

假设我有一个类,其中包含一组标有 [Import] 属性的字段,其中所有这些字段都禁止 recomposition .

在某些时刻,使用 new MyClassWithInjectedFields(...) 实例化此类,并使用 MEF 框架注入(inject)所有相应的依赖项 - 没什么大不了的,只是双射 Export-To-Import 映射。

Questions:

  • Is it safe to assume that in this case the values of injected fields will remain the same until the class instance is garbage collected?

  • Or maybe there are some rare / obscure cases when they might get changed implicitly by MEF in runtime? Perhaps, when someone unloads or reloads the assembly used for dependency resolution?

(我是 MEF 的新手,我不太确定是否有办法在运行时影响依赖关系图,但是,很明显,可能会有)。

最佳答案

1) MEF 没有对 GC 做任何特殊的事情,因此实例不会被 GC,直到不再有对对象的事件引用。

2) 如果导入未标记为可重组,则 MEF 只会更改导入的值。您不能卸载\重新加载正在运行的 .NET 进程中的程序集,您可以卸载 AppDomain,但这样做实际上会强制终止对象引用,但 MEF 不会执行任何特殊操作来重置它们。

关于c# - MEF导入解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12799283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com