Can anyone help me with Import and ImportingConstructor attributes in MEF with relevant examples and when to use ? what is the use of [Import(AllowDefault = true)] ?
From my understanding of MEF:
Export attribute is defined on Class of type T where T is interface and to create a instance of that class Import attribute should be defined on the reference variable like below
[Export(typeof(ICalculator))]
class MySimpleCalculator : ICalculator
{
// Implement the interface
}
class MyMainClass
{
// MEF engine creates an instance as Export attribute is defined
// on MySimpleCalculator
[Import(typeof(ICalculator))]
public ICalculator calculator;
}
If Multiple Exports of type T are defined in a given assembly then we can use ImportMany attribute.
So now can anyone explain when to use Import and ImportingConstructor and also AllowDefault attribute in the constructor ?
It would be great if someone can explain with better examples.
Any help would be appreciated. Thanks