Managed Extensibility Framework as of now is a new model that deals with Extensibility in application by giving you a standard set of rules by which the vendor who exports components can be related easily to the vendors that imports software components. Hence MEF rules as a standard way of defining extensibility in application.
In MEF architecture we have a number of components that we need to address :
Import : Import is an attribute that marks an object of a particular type importable from 3rd party software vendors. Thus when you mark a Type as Import, it will indicate that the Type will get the object at runtime when Parts are composed.
Export : Export is an attribute that marks an object of a particular type exportable from a 3rd party software vendors. This will ensure that the object can be created at runtime and plugged in to some host application which is importing this component.
Compose : Compose is another important part of MEF architecture where the Imports and Exports are mapped together and relationship between them is created. Compose is done within a IOC container which writes the dependencies between components.
When you export some component the whole object is discovered at runtime when the Parts (a set of Import and Export) are created. The CompositionContainer discovers all the Parts from a Catalog you specify within it and writes the dependencies between each component. Now sometimes, you need to have some portion of your code not discoverable by the Catalog
. PartNotDiscoverable
is a special attribute that helps you to deal with this situation.
[PartNotDiscoverable] public Action MyActionDelegate { get; set; }
In this case the MyActionDelegate will not be discovered as a Part. The Catalog simply ignores this type as a Part and hence this portion of the code remains secure from external components.
It should be noted, PartNotDiscoverable attribute replaces the legacy [CompositionOptions(DiscoveryMode = DiscoveryMode.Never)] attribute.
Read more about it from the links :
Managed Extensibility Framework – A Look
Steps to write a plugin based application with MEF
Thank you for reading.
Pingback: Dew Drop – September 1, 2011 | Alvin Ashcraft's Morning Dew