MEF 容器实例并不是不可变的。若是目录支持改变(像监控目录变更)或者在运行时添加/移除部件均可能发生改变。之前,你不得不作出改动而且调用 CompositionContainer 上的 Compose 方法。在 Preview 4 release上,咱们已经介绍对批量组合的支持。编程
var batch = new CompositionBatch(); batch.AddPart(partInstance1); batch.AddPart(partInstance2); batch.RemovePart(part3); container.Compose(batch);
// creates a CompositionBatch and calls AddPart on all the passed parts followed by Compose container.ComposeParts(partInstance1, partInstance2,... ); // creates a CompositionBatch and calls AddExportedValue<T> followed by Compose. container.ComposeExportedValue<IFoo>(instanceOfIFoo);