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);