This is a mirror of official site: http://jasper-net.blogspot.com/

Setting up Policies for Extensible Parts in MEF

| Thursday, September 8, 2011
    Part Lifetime is one of the most important hindrances that we face while working with MEF. It is very important to understand how the parts are going to be shared between plugins such that having been so much open ended, 3rd party plugins remain separated to the objects that you do not want to be shared outside.  In this post I am going to define how Part creation policies can be setup on an object to ensure how the object needs to behave in the CompositionContainer.

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: https://chart.googleapis.com/chart?chs=80x80&cht=qr&choe=UTF-8&chl=http://dailydotnettips.com/2011/09/07/setting-up-policies-for-extensible-parts-in-mef/

Posted via email from Jasper-net

0 comments: