This project has moved and is read-only. For the latest updates, please go here.

Curious if MEF can handle these situations

Nov 29, 2011 at 5:52 PM

I'm going through the framework right now, but I wanted to jump ahead to see if I'll hit a dead end here.  There are some oddball cases I have to deal with that I was hoping MEF could help me handle.  We want to have plugins in our applications here generally, but we run into all kinds of odd stuff.  Some of it is unsound practice but I wanted to accomodate it if I could.

First, how well does MEF handle multiple instances of an assembly?  We have cases where we'd have two different versions of the same assembly in memory.  I've worked out how that works manually with application domains, and it's not the kind of thing I normally want to have to maintain. 

Second, can MEF handle reloading an assembly if it has been changed?  The use case here would be a developer loading in their plugin, finding some goof, then wanting to load a rebuild of the same thing.  I don't expect them to change any of the assembly information, since they haven't in the past.

Third, is there a way to dynamically add new interfaces for it to load and manage?  This comes up because the main application also serves like a traffic cop for routing plugins to other plugins so they can use the interfaces to do their thing.  The main application isn't calling any of the stuff directly.  The examples I see involve the plugins being added as properties to a class.  This would be a static method, and I don't see how it would work for dynamic cases.  All I can think of is one property handling a list of some base interface type, and having to disambiguate stuff using reflection.  MEF wouldn't give me anything there.

I'll grant these cases are pretty bizarre, but I hope we can avoid the "x instead of y" answers that just question why I'm even doing this.  Just let it be a given these situations have already come up when trying our own manual system and I'd like to get something working cleanly to accomodate them.

Nov 29, 2011 at 9:18 PM


I think that the answer is probably "no" in each of these cases. MEF does not include any support for assembly unloading/isolation/versioning beyond what is already in the framework. It is possible that MEF will even introduce additional complexity in the cases you've described.

You are undoubtedly the best judge of your requirements here. Just in case it supports a course of action you are already considering, I would be looking to improve build/integration/deployment/hosting techniques to avoid this kind of hot code loading/swapping before making architectural changes to work around it.

Hope this helps,