Configurable Definition Provider

The configurable definition a provider enables part to be defines using a declarative syntax with the help of the configuration file. As of Preview 1, the schema for the XML has not been set in stone and is likely to change in future releases. Future releases will also contain the needed XSD file to add intellisense support for the configuration section.

var configurableCatalog =
  new DefinitionProviderPartCatalog<ConfigurableDefinitionProvider>("mef.configuration");

The first thing you need to do, to start using configuration based definitions, is to setup the configuration section in the config file.

<configSections>
  <section
    name="mef.configuration"
    type="MefContrib.Models.Provider.Definitions.Configurable.PartCatalogConfigurationSection, MefContrib.Models.Provider" />
</configSections>

Once that has been done you can start adding parts to the <parts> collection element.

<mef.configuration>
  <parts>
  </parts>
</mef.configuration>

The parts element contains one or more <part> elements.

Part element

The part element declares a composable part definition for MEF. It contains two child elements; exports and imports, both of them are optional but at least one of them needs to be present in order for a part declaration to be valid.

<part type="assembly-qualified-name">
  <exports / >
  <imports />
</part>

The assembly-qualified-name is a string in the format of “Namespace.Class, Assembly” but can also contain more evidence to pinpoint a specific type and assembly.

Export element

The export element declares an export on the part it’s defined. The full syntax of the export element is as follows

<export member=”” contract=””>
  <metadata>
    <add name=”” value=””>
  </metadata>
</export>

The following attributes and elements are available.

Name Description
Member The member attribute is used to specify which member of the part, that the export is defined on, should be the actual export. This attribute is optional and if it is omitted then the entire part will be used as the export. You would use this when you want to export an entire class.
Contract The contract attribute is the name of the contract which the export should conform to. This should be the same as the contract on the import which the export should satisfy.
Metadata The metadata element is optional and is used to define metadata which is assigned to the export when it’s created. The added elements are a simple name/value pairs where the name is a string and the value will internally be treated as an object.

Import Element

The import element declares an import on the part it’s defined. The full syntax of the import element is as follows

<import member=”” contract=”” allowDefault=”true|false” isPrerequisite=”true|false” isRecomposable=”true|false”>
    <metadata>
      <add name=””>
    </metadata>
  </import>
</import>

The following attributes and elements are available.

Name Description
Member The member attribute is used to specify which member of the part, that the import is defined on, should be the actual import. Valid values are names of fields and properties.
Contract The contract attribute is the name of the contract which the import should conform to.
AllowDefault Sets a value indicating whether the property or field will be set to its type's default value when an export with the contract name is not present in the container.
IsPrerequisite Sets a value indicating whether the import definition is required to be satisfied before a part can start producing exported objects.
IsRecomposable Sets a value indicating whether the import definition can be satisfied multiple times.
Metadata The metadata element is optional and is used to define metadata which is assigned to the import when it’s created. The name of the added elements will be added to the collection of required metadata of the import.

Last edited Mar 1, 2009 at 3:22 PM by TheCodeJunkie, version 2

Comments

No comments yet.