I am playing around with the new System.ComponentModel.Composition namespace in .NET 4.0 beta 2, also known as the Managed Extensibility Framework.
I use the following C# example where a Monkey
imports a Banana
:
public interface IBanana
{
}
[Export(typeof(IBanana))]
public class Banana : IBanana
{
}
public class Monkey
{
[Import(typeof(IBanana))]
public IBanana Banana { get; set; }
}
However, when I try to compose the monkey as follows then I get an InvalidOperationException
with the message "This object has not been initialized - the property 'SourceProvider' must be set.":
var exportProvider = new CatalogExportProvider(new TypeCatalog(typeof(Banana)));
var container = new CompositionContainer(exportProvider);
var monkey = new Monkey();
container.ComposeParts(monkey);
What am I missing here? I am aware that I can pass the catalog directly without wrapping it in a CatelogExportProvider, but shouldn't the above also work?