http://blogs.clariusconsulting.net/pga

Pablo Galiano's Blog

Go Back to
pga′s Latest post

VS 10 beta 1 Exporting MEF parts from a VS Package (part 3)

***Disclaimer: This information applies to Visual Studio 2010 Beta 1 only.***

Â

This is the final part of this post series. I will show how to get the available exports.

To get the available exports I will use a command under the Tools menu:

image

The menu callback get the first registered IMessagingService export and calls the display message method:

private void MenuItemCallback(object sender, EventArgs e)
{
    var componentModel = base.GetService(typeof(SComponentModel)) as IComponentModel;
    var messaging = componentModel.GetExtensions<IMessagingService>().FirstOrDefault();

    messaging.DisplayMessage("Hello MEF");
}

Â

image

Â

Couple of points:

  • The SComponentModel service is used to get the available extensions
  • The GetExtension method calls the GlobalCompositionContainer, which find all availables <TExport> in the list of containers that are maintaned by the VsExportProviderService class

Â

Pablo

Comments