我有 2 个程序集:
组装 1:
interface IWeapon {
int Might { get; }
}
[Export("sword")]
public class Sword : IWeapon {
public int Might {
get { return 10; }
}
}
组装 2:
interface IWeapon {
int Might { get; }
}
var catalog = new AssemblyCatalog(typeof(Ninja.Sword).Assembly);
var container = new CompositionContainer(catalog);
// not allowed to use the IWeapon def in assembly 2
var sword = container.GetExportedValue<IWeapon>("sword");
我知道如何让它发挥作用。我可以向 MEF(托管可扩展性框架)询问对象,或者让它导出正确的 IWeapon 而不仅仅是按名称导出对象。
如果实现了所有接口点,MEF 可以为我输入“鸭子”并返回代理对象吗?