【发布时间】:2011-09-13 07:41:37
【问题描述】:
考虑以下情况:
[Export]
class A { }
class B
{
[Import]
private A a;
}
// Instantiates class B.
class C
{
public C(Type type){ /*Instantiate Class B here.*/}
public void PerfomOperationUsingClassB() { }
}
class D
{
void Initialize()
{
var catalog = new AssemblyCatalog(Assembly.GetAssembly(typeof(A)));
var container = new CompositionContainer(catalog);
// Is there any way to compose A with B?
C c = new C(typeof(B));
c.PerfomOperationUsingClassB();
}
}
问题:我可以访问类“A”和“B”,但类“C”位于我无法修改的程序集中(因此无法修改类“C”)。有没有办法组成“A”和“B”?
【问题讨论】:
-
啊!有代码格式化!清理
<br>和&nbsp;的混乱并不好玩。 -
您想消除对 C 类的使用,还是强制调用 c.PerformOperationUsingClassB?
-
现在可以用 MEF 导入私人会员吗?
-
哦,酷!那我一定要试试新的东西!
-
@Matt New Bits? Mef 附带 .Net 4
标签: .net ioc-container mef composition