I have a MEF-based application that can be customized with plugins. This application has several imported parts, and I want to remove some of them at runtime (to be able to delete the .dll that contains them) when a user decides to get rid of that plugin.
CompositionBatch would do what I need, but it needs ComposablePart
instances as input parameters for RemovePart()
method, and I only have plain objects that implement ISomething interface, or ComposablePartDefinition
instances in the AggregateCatalog
. So the my question is:
- How can I find the ComposablePart instance that represents the imported object that I want to get rid of?
- Or alternatively: how do I get the list of ComposablePart objects that belong to a certain .dll?
I would use something like follows:
var parts = Container.Catalog.Parts
.Where(p => iDontNeed(p))
.Select(p => howDoIConvertComposablePartDefinition2ComposablePart(p));
var batch = new CompositionBatch();
parts.ToList().ForEach(part => batch.RemovePart(part));
Thank you