Does MEF support continuous discovery?

Nov 14, 2008 at 1:35 AM
I've only looked at MEF for 5 minutes, so this may be an obvious question...

While my application is running, the user could drop a plugin dll into a directory.  Can MEF detect this and update collection based Imports?  So...

[Import(typeof(IPlugin)]
public IEnumerable<IPlugin> _plugins;

Will the above collection only get populated once, or will new plugins keep getting added as my program is running?

From what I've read so far, I dont think this will be the case, so maybe this is a feature request. :-)

Nov 14, 2008 at 2:12 AM
It does support this. Our DirectoryPartCatalog has a boolean in the constructor to watch the directory. Parts in MEF are recomposable. That means if you import a collection of foos and then a new foo shows up in the catalog, then the collection will be updated. Currently this is the default behavior, we are planning to make it opt-in.

Note: We don't make any threading guarantees when importing. If you are iterating through a collection and recomposition occurs then the iterating will fail. You need to take the proper precautions.

Glenn

-----Original Message-----
From: "bfurtwangler" 
To: "Glenn Block" 
Sent: 11/13/2008 5:35 PM
Subject: Does MEF support continuous discovery? [MEF:39900]

From: bfurtwangler

I've only looked at MEF for 5 minutes, so this may be an obvious question...

While my application is running, the user could drop a plugin dll into a directory. Can MEF detect this and update collection based Imports? So...

[Import(typeof(IPlugin)]
public IEnumerable _plugins;

Will the above collection only get populated once, or will new plugins keep getting added as my program is running?

From what I've read so far, I dont think this will be the case, so maybe this is a feature request. :-)

Nov 17, 2008 at 4:45 PM
What would happen when a dll gets overwritten by a newer version dll while an instance of the older is still being consumed?
Nov 17, 2008 at 8:21 PM
The dll is locked and you will not be able to overwrite it.
Nov 25, 2008 at 8:50 PM
Ganesh

One approach you can look into is using shadow copying. If you set up your app domain to shadow copy, then the assemblies you drop into your extensions folder will not be locked. Once you update the folder, recomposition will occur.

Glenn
Nov 26, 2008 at 2:35 PM
Glenn,
that is a possibility. But I guess that should be part of the class rather than MEF itself.