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.

Example:

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.

Tomer

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.

E.g.

IEnumerable<Export> matching = container.GetExports(

  new ContractBasedImportDefinition(

    AttributedModelServices.GetContractName(type),

    AttributedModelServices.GetTypeIdentity(type),

    Enumerable.Empty<string>(),

    ImportCardinality.ExactlyOne,

    false,

    false,

    CreationPolicy.Any));

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,

Nick

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.

 Thanks!