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

Markups for importing parts via XAML

Aug 11, 2009 at 7:19 PM
Edited Aug 11, 2009 at 7:21 PM

I'm trying to create XAML markups for importing parts via XAML and I have to use a non-generic GetExportedValue method. Unfortunately this method is internal, and the funny thing is that the generic methods are using it.


object value = GetExportedValue(type);

To overcome this I’ve added an overload method to the container, but this solution is temporary and will only last until the release of MEF.

Is it possible to add this API to future versions of MEF, and finally to the .NET Fx?

I think that it would be great for getting exports defined by configuration files, DB, reflection, XAML, etc.


Aug 11, 2009 at 7:27 PM

Thanks for the feedback Tomer.

We'll consider additional overloads in the future, but currently you can achieve the results you want using ContractBasedImportDefinition.


IEnumerable<Export> matching = container.GetExports(

  new ContractBasedImportDefinition(








object value = matching.Single().Value;


Admittedly this is very verbose, but if you want to you can package it up as an extension method on ExportProvider.

Hope this helps,


Aug 11, 2009 at 7:31 PM

This is excactly what I've been looking for. I'll be glad to have it as an additional oveload to the container in future versions.