Have MEF use any available builds.

This is the first time I am using the Framework Managed Extensibility Framework in Visual Studio 2010 beta using System.ComponentModel.Composition from .net-4.0.

I was unable to get CompositionContainer to find my implementation assemblies using the two alternative routines below.

First attempt (this worked in an earlier version of the MEF code):

var composition = new CompositionBatch();
composition.AddPart(this);
var container = new CompositionContainer(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
container.Compose(composition);

Second attempt (I think this worked in beta 1):

var aggregateCatalog = new AggregateCatalog(
    new AssemblyCatalog(Assembly.GetExecutingAssembly()),
    new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
var compositionContainer = new CompositionContainer(aggregateCatalog);
compositionContainer.ComposeParts(this);

Is there a new way to do this in beta 2?

EDITOR: It had nothing to do with the composition. I had a static property representing my imported implementation:

[Import] public static ILog Log { get; set; }

which was supposed to be:

[Import] public ILog Log { get; set; }

I marked Daniel’s answer as accepted because the debug sage’s advice more thoroughly solved the problem.

+5
2

? , , ? GetExports(), ?

, , aggregateCatalog, , . , , , , . , , [Import] [ImportMany] / , , .

+1

Compose SoapBox, , DirectoryCatalog, . , .NET 4, MEF:

    private bool Compose()
    {
        var catalog = new AggregateCatalog();
        catalog.Catalogs.Add(new DirectoryCatalog("."));

        _container = new CompositionContainer(catalog);

        try
        {
            _container.ComposeParts(this);
        }
        catch (CompositionException compositionException)
        {
            MessageBox.Show(compositionException.ToString());
            return false;
        }
        return true;
    }
0

All Articles