MEF, IServiceProvider and Testing Visual Studio Extensions
In the latest and greatest version of Visual Studio, MEF plays a critical role, one that makes extending VS much more fun than it ever was.
So typically, you just [Export] something, and then someone [Import]s it and that's it. MEF in all its glory kicks in and gets all your dependencies satisfied.
Cool, you say, so let's now import
ITextTemplating
and have some
T4-based
codegen going! Ah, if only it was that easy. Turns out by
default, none of the VS built-in services are exposed to
MEF, apparently because there wasn't enough time to analyze
the lifetime, initialization, dependencies, etc. for each
one before launch, which makes perfect sense. You don't want
to blindly export everything now just in case. There's also
the whole VS package initialization thing which in this
version of VS is not so transparently integrated with the
MEF publishing side (i.e. a MEF export from a package can
get instantiated before its owning package, and in fact, the
package can remain unloaded forever and the export will
continue to be visible to anyone)....