It is true that MEF is very well constructed and everything could be defined just in forms of an attribute, Part lifetime can also be set using a special attribute called PartCreationPolicy.
[PartCreationPolicy(CreationPolicy.NonShared)]
public Action MyActionDelegate { get; set; }
This means the container will secure the object Action to be shared to any other import in the container either directly or indirectly. There are three states of CreationPolicy :
Shared : This means the object will be shared in the container for any other import statement. This is the default settings for any Export and content can associate with any other component.
Non-Shared : This means the object will not be shared either directly or indirectly. This is used only when you do not want to share your object and risk being exposed to 3rd party libraries.
Any : This settings will choose either shared or non-shared value.
Read more: Daily .Net Tips
QR: