ContractType

Could someone please explain to me when something needs to be decorated with the ContractTypeAttribute? I've created a simple interface IContract which I've then implemented in a concrete class NullContract. This is then exported (tried using both the
type and contractName overloads) and imported (same as with the export, I tried using both the type and contractName overload) and in both cases it works without me having to decorate the IContract interface with the ContractTypeAttribute

I had a look in the Extensible File Explorer sample and I see that the INavigationService interface has been decoreated with
the attribute but I cannot figure out why.

Hmmm... checked the source code and I'm thinking this is normally optional but if you want to set a specific identifier for your contract at design time that is not the same as the type.FullName then this would be pretty handy.

Could someone please explain to me when something needs to be decorated with the ContractTypeAttribute? I've created a simple interface IContract which I've then implemented in a concrete class NullContract. This is then exported (tried using both the
type and contractName overloads) and imported (same as with the export, I tried using both the type and contractName overload) and in both cases it works without me having to decorate the IContract interface with the ContractTypeAttribute

I had a look in the Extensible File Explorer sample and I see that the INavigationService interface has been decoreated with the attribute but I cannot figure out why.

You mean if you want to be able to use Import("Full.Contract.Name")/Export("Full.Contract.Name") or even Import("Full.Contract.Name.Custom")/Export("Full.Contract.Name.Custom") ? Because both just fine without having
to use the ContractTypeAttribute.

One thing that I saw was that using the ContractTypeAttribute you provide the meta data type difrectly, but I havent had a chance to investigate how to consume this information (I've used my own Metadata contracts and derives attributes using the MetadataAttribute,
but not the MatedateViewType parameter of the ContractTypeAttribute)

Magnus is right. ContractTypeAttribute is used to specify a type is to be treated as a contract type, but it is not required. You can use it change the contract name to something other than the one derived from the contract type. The MetadataType property
is not used anywhere else by MEF so far.

ContractType has been introduced so that the types that were created to serve as contracts can be easily discovered. This creates an opportunity for relatively rich tooling support (contracts - together with the suggested metadata view type - present in
the system can be discovered by tools and, for instance, boilerplate import/export code can be generated). Also, yes, you change the name of the contract if you wish to.

Zhenlan is right - the composition engine itself largely doesn't care about contract types (with the exception of the name change), however we do
recommend that ContractType attribute is used if the type has been explicitly designed to serve as a contract, so as to enable future tools.

@olegl, does this mean that, like zhenlan suggests, the MetadataType property on the ContractTypeAttribute is not used internally by the MEF (as of right now), but has also been introduced so that metadata can easily be discovered by tools and
so on?