The Wim example has basic ideas, but instead of directly clicking on the container, I suggest you make Lazy ImportMany, for example:
[Export]
public class MyApplication
{
[ImportMany(typeof(IPlugin))]
public IEnumerable<Lazy<IPlugin>> Plugins { get; set; }
}
Then you can initialize the plugins one at a time and catch any errors from them, for example:
void InitializePlugins()
{
foreach (Lazy<IPlugin> plugin in Plugins)
{
try
{
plugin.Value.Initialize();
}
catch (CompositionException e)
{
}
}
}
The actual plugin will not be created until you click. Highlight the first time, and that's when errors will occur if the plugin has errors in the constructor or import settings. Also note that I will catch a CompositionException, which will be what will exit the .Value call if the plugin does something wrong.
source
share