I have an instance of an object, and I want to end with the MEF directory that contains this instance of the object, exported as a specific type of interface. How can i do this?
TypeCatalog does not work here because (a) it creates a new instance instead of the existing one, and (b) this requires the type to have the [Export] attribute. In my case, the instance comes from the MEF metadata system, so MEF creates the base type, and I cannot add attributes to it.
As far as I can tell, the usual advice is: if you have an existing instance, you should add it to the container (for example, via CompositionBatch ), and not to the directory. But when I add this instance, I also add all types of AssemblyCatalog types, all in the same operation. I also want to be able to remove all these types later. It makes more sense to me to collect everything in AggregateCatalog. That way, I can add both the assembly and the instance in one atomic operation, and I can delete them all the same way.
For instance:
The part I donโt know how to do is "MakeCatalogFromInstance". How to create a directory containing an existing instance (registered as a specific type)?
Or, alternatively, if Iโm all wrong about this, is there a better way to connect the entire directory and an existing instance to MEF at the same time, with the ability to disconnect them again again and replace them with something else?
source share