Http://msdn.microsoft.com/zh-cn/magazine/ee291628.aspx
There are two import methods: (1)Import through attributes and fields
public class ViewFactory{ [Import] public SalesOrderView OrderView { get; set; }}
(2)Import using Constructors
Public class viewfactory
{
[Importingconstructor]
Public viewfactory (salesorderview)
{
}
}
Import through Constructor (usually called constructor injection). When importing constructor,MEF assumes that all parameters are importedSo that you do not need to use the import feature.
It is a matter of personal preferences to import data through constructors rather than attributes,
However, attribute import has a wide range of applicability, especially when attributes exist.When a part is not instantiated by MEF.
The constructor parameter is not supported either.Reassemble.
You can set requiredcreationpolicy for Attribute import, but importingconstructor does not seem to work.
When importing attributes, the constructor does not seem to be able to access the import attributes. This is strange. It seems that the imort attribute can be accessed only after the constructor is executed.