Can plugins loaded with MEF resolve their own internal dependencies with the same MEF container for

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-06-15T17:39:25Z Indexed on 2010/06/15 17:42 UTC
Read the original article Hit count: 1125

Filed under:
|
|

From my experimentation, I think the answer is "kind of", but I could have made a mistake.

I have an application that loads appliance plugins with MEF. That part is working fine.

Now let's say that my BlenderAppliance wants to resolve several of its dependencies with MEF, which each implement IApplianceFeature. I've just used the ImportMany attribute to my plugin. I made sure to create the plugin using MEF so that the Imports work properly.

I said "kind of" because some of the plugin's internals (i.e. the model) are loading with MEF just fine, but the IApplianceFeatures aren't. The difference here is that the IApplianceFeatures are themselves, assemblies. And at the moment, they are in one folder above that of the plugin itself, i.e.

+ application folder
| IApplianceFeature1.dll
| IApplianceFeature2.dll
+---+ plugin folder
    | BlenderAppliance.dll

Now if my application uses an AggregateCatalog to load the "." and ".\plugins" folders, why doesn't it ever load the IApplianceFeature assemblies for me?

Is it possible / advisable to have the plugin create its own MEF container to resolve its dependencies, or does really nasty stuff happen? If you have any stories about this scenario, please share. :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about plugins