So, here is a questions about the newly released MEF 4.0 (Managed Extension Framework).
In MEF you can use the ImportingConstructor attribute to decorate a contructor, like so:
class Test
{
[ImportingConstructor]
public Test(IMessageSender messageSender)
{
}
}
However, I am not able to find example code that actually resolves this Import.
There are plenty of composition examples like below:
private void Compose()
{
var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
It composes parts of this, meaning the instance has already been already constructed.
Alternatively, you may find code like so:
var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
Employee employee = new Employee()
container.ComposeParts(employee);
But again, the constructor of Employee has already been called before composition takes place.
My question is this: how do you let MEF invoke the constructor (i.e. create an object) of an Imported constructor?
I would have expected something like:
container.CreateObject("name" or type)
Any pointers will be greatly appreciated.