ContractType

Nov 27, 2008 at 2:35 PM
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.
Nov 27, 2008 at 2:54 PM
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.

But maybe I got it wrong?

M.

On Thu, Nov 27, 2008 at 15:35, TheCodeJunkie <notifications@codeplex.com> wrote:

From: TheCodeJunkie

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.

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--
Magnus Mårtensson
Senior Consultant - Scrum Master - MCSD, MCTS
Dotway AB

Tel: +46 (768) 51 00 36

http://blog.noop.se/
Nov 27, 2008 at 3:04 PM
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)
Dec 1, 2008 at 10:00 PM
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.

Zhenlan
Dec 1, 2008 at 10:34 PM
Edited Dec 1, 2008 at 10:35 PM
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.
Dec 11, 2008 at 3:00 PM
@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?
Dec 13, 2008 at 2:22 AM
That's correct, at this point we do not use this information at all, however we might in the future. We recommend that you do annotate your contracts with this information, if it's meaningful
Oleg