<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>The Wit and Ramblings of David Giard - MEF</title>
    <link>http://www.davidgiard.com/</link>
    <description>Demanding rigidly defined areas of doubt and uncertainty</description>
    <language>en-us</language>
    <copyright>David Giard</copyright>
    <lastBuildDate>Mon, 16 Aug 2010 10:42:22 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>davidgiard@davidgiard.com</managingEditor>
    <webMaster>davidgiard@davidgiard.com</webMaster>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=1b548034-5d32-40ec-96d1-213464cf1be3</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,1b548034-5d32-40ec-96d1-213464cf1be3.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,1b548034-5d32-40ec-96d1-213464cf1be3.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1b548034-5d32-40ec-96d1-213464cf1be3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img src="content/binary/TechnologyAndFriends.gif" border="0" />
        </p>
        <p>
          <strong>Episode 110</strong>
        </p>
        <p>
          <a href="http://technologyandfriends.com/archive/2010/08/16/tf110.aspx">Jeremy Likness
on MEF</a>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1b548034-5d32-40ec-96d1-213464cf1be3" />
      </body>
      <title>Jeremy Likness on MEF</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,1b548034-5d32-40ec-96d1-213464cf1be3.aspx</guid>
      <link>http://www.davidgiard.com/2010/08/16/JeremyLiknessOnMEF.aspx</link>
      <pubDate>Mon, 16 Aug 2010 10:42:22 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img src="content/binary/TechnologyAndFriends.gif" border="0"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 110&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://technologyandfriends.com/archive/2010/08/16/tf110.aspx"&gt;Jeremy Likness
on MEF&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1b548034-5d32-40ec-96d1-213464cf1be3" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,1b548034-5d32-40ec-96d1-213464cf1be3.aspx</comments>
      <category>MEF</category>
      <category>Technology and Friends</category>
      <category>Video</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=4e102254-fce3-4118-b15e-4fe1e2bcffe4</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,4e102254-fce3-4118-b15e-4fe1e2bcffe4.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,4e102254-fce3-4118-b15e-4fe1e2bcffe4.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4e102254-fce3-4118-b15e-4fe1e2bcffe4</wfw:commentRss>
      <title>Slides and demos from MEF presentation</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,4e102254-fce3-4118-b15e-4fe1e2bcffe4.aspx</guid>
      <link>http://www.davidgiard.com/2010/02/08/SlidesAndDemosFromMEFPresentation.aspx</link>
      <pubDate>Mon, 08 Feb 2010 03:36:13 GMT</pubDate>
      <description>&lt;p&gt;
I gave a talk on MEF a numbe of times during January. You can get the slides and demo
from the link below
&lt;/p&gt;
&lt;p&gt;
&lt;iframe style="PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #fcfcfc; PADDING-LEFT: 0px; WIDTH: 98px; PADDING-RIGHT: 0px; HEIGHT: 115px; PADDING-TOP: 0px" title=Preview marginheight=0 src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedicon.aspx/Presentations/MEF" frameborder=0 marginwidth=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;
or you can view the slides below:
&lt;/p&gt;
&lt;div style="width:425px;text-align:left" id="__ss_3100686"&gt;&lt;a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/dgiard/managed-extensibility-framework-2010-01" title="Managed Extensibility Framework 2010 01"&gt;Managed
Extensibility Framework 2010 01&lt;/a&gt;
&lt;object style="margin:0px" width="425" height="355"&gt;
&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=managedextensibilityframework-2010-01-100207213825-phpapp01&amp;stripped_title=managed-extensibility-framework-2010-01" /&gt;
&lt;param name="allowFullScreen" value="true" /&gt;
&lt;param name="allowScriptAccess" value="always" /&gt;&lt;embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=managedextensibilityframework-2010-01-100207213825-phpapp01&amp;stripped_title=managed-extensibility-framework-2010-01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"&gt;View
more &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/dgiard"&gt;David
Giard&lt;/a&gt;.
&lt;/div&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=4e102254-fce3-4118-b15e-4fe1e2bcffe4" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,4e102254-fce3-4118-b15e-4fe1e2bcffe4.aspx</comments>
      <category>Community</category>
      <category>MEF</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=a4a9f9e3-421a-4836-8026-2df983740a3c</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,a4a9f9e3-421a-4836-8026-2df983740a3c.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,a4a9f9e3-421a-4836-8026-2df983740a3c.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a4a9f9e3-421a-4836-8026-2df983740a3c</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I smiled as I drove across the state line into Michigan Friday morning. I was returning
home from spending most of the week in Ohio, speaking at user groups throughout the
state. 
</p>
        <p>
I spoke about Managed Extensibility Framework at four user groups over three days
in four different cities.
</p>
        <p>
Tuesday, I spoke at an internal user group of the Cincinnati Financial Corporation,
before heading over to the Cincinnati .Net User Group in Mason, OH. Wednesday I drove
up to Dayton to speak at the Dayton .Net Developers Group. Thursday I presented to
a packed house in Columbus at the Central Ohio .Net Developers Group.
</p>
        <p>
The trip was a great success. At each stop, the crowd was larger than their average
meeting.  Everywhere I went I heard probing questions that indicated that I was
communicating the concepts of MEF and loosely-coupled architecture. This was gratifying
as most people had no idea what MEF was when they arrived at my talk.
</p>
        <p>
The best of the trip was that I had a chance to see old friends. I spent ten years
living and working in the Cincinnati area and many of my former colleagues came out
to hear me. Some I hadn't seen in years. I once worked for a Columbus-based company,
and through them I got to know much of the developer community in that area and I
saw many familiar faces in Central Ohio this week. Tuesday and Thursday night, we
went out for drinks after the meeting, which gave me a chance to talk one-on-one with
a lot of smart people. 
</p>
        <p>
I also got a chance to see the inside of the Sogeti offices in Cincinnati, Dayton
and Columbus and talk with some of the team in these offices.
</p>
        <p>
I had a great time on this tour and I'd love to do another one. 
</p>
        <p>
Thank you to all who came out to hear my talk. Thank you especially to Mike Wood,
Jim Holmes and James Bender, who allowed me to stay at their homes on my trip.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=a4a9f9e3-421a-4836-8026-2df983740a3c" />
      </body>
      <title>MEF in the Buckeye state</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,a4a9f9e3-421a-4836-8026-2df983740a3c.aspx</guid>
      <link>http://www.davidgiard.com/2010/01/31/MEFInTheBuckeyeState.aspx</link>
      <pubDate>Sun, 31 Jan 2010 05:07:49 GMT</pubDate>
      <description>&lt;p&gt;
I smiled as I drove across the state line into Michigan Friday morning. I was returning
home from spending most of the week in Ohio, speaking at user groups throughout the
state. 
&lt;/p&gt;
&lt;p&gt;
I spoke about Managed Extensibility Framework at four user groups over three days
in four different cities.
&lt;/p&gt;
&lt;p&gt;
Tuesday, I spoke at an internal user group of the Cincinnati Financial Corporation,
before heading over to the Cincinnati .Net User Group in Mason, OH. Wednesday I drove
up to Dayton to speak at the Dayton .Net Developers Group. Thursday I presented to
a packed house in Columbus at the Central Ohio .Net Developers Group.
&lt;/p&gt;
&lt;p&gt;
The trip was a great success. At each stop, the crowd was larger than their average
meeting.&amp;nbsp; Everywhere I went I heard probing questions that indicated that I was
communicating the concepts of MEF and loosely-coupled architecture. This was gratifying
as most people had no idea what MEF was when they arrived at my talk.
&lt;/p&gt;
&lt;p&gt;
The best of the trip was that I had a chance to see old friends. I spent ten years
living and working in the Cincinnati area and many of my former colleagues came out
to hear me. Some I hadn't seen in years. I once worked for a Columbus-based company,
and through them I got to know much of the developer community in that area and I
saw many familiar faces in Central Ohio this week. Tuesday and Thursday night, we
went out for drinks after the meeting, which gave me a chance to talk one-on-one with
a lot of smart people. 
&lt;/p&gt;
&lt;p&gt;
I also got a chance to see the inside of the Sogeti offices in Cincinnati, Dayton
and Columbus and talk with some of the team in these offices.
&lt;/p&gt;
&lt;p&gt;
I had a great time on this tour and I'd love to do another one. 
&lt;/p&gt;
&lt;p&gt;
Thank you to all who came out to hear my talk. Thank you especially to Mike Wood,
Jim Holmes and James Bender, who allowed me to stay at their homes on my trip.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=a4a9f9e3-421a-4836-8026-2df983740a3c" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,a4a9f9e3-421a-4836-8026-2df983740a3c.aspx</comments>
      <category>Community</category>
      <category>MEF</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=1a3dddaf-76aa-45e4-bb28-267b3d55df8c</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,1a3dddaf-76aa-45e4-bb28-267b3d55df8c.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,1a3dddaf-76aa-45e4-bb28-267b3d55df8c.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1a3dddaf-76aa-45e4-bb28-267b3d55df8c</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Juanary is offically MEF month. I have scheduled "Extending Your Application with
the Managed Extensibility Framework (MEF)" at least 6 times this month. The first
time was last week, when I delivered a Grok Talk at Sogeti that was available via
Live Meeting.
</p>
        <p>
The following presentations will all be about MEF
</p>
        <ul>
          <li>
Fri Jan 15 at 3PM, I will be delivering a vendor session at CodeMash in Sandusky,
OH. 
</li>
          <li>
Tue Jan 26 at Noon, I will deliver a presentation to Financial Corp User
Group in Cincinnati, OH. 
</li>
          <li>
Tue Jan 26 at 6PM, I will present at the Cincinnati .Net User Group in
Mason, OH 
</li>
          <li>
Wed Jan 27 at 6PM, I will present at the Dayton .Net User Group in
Dayton, OH 
</li>
          <li>
Thu Jan 28 at 6PM, I will present at the Central Ohio .Net User Group in Columbus,
OH</li>
        </ul>
        <p>
In addition, I will deliver two presentations Fri Jan 22 at the State of MI Developer
Briefing in Lansing, MI. 
</p>
        <ul>
          <li>
At 1PM, I will deliver my MEF presentation (of course).<br />
At 2:30PM, I will present on "Speeding your application with Microsoft Velocity".<br /></li>
        </ul>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1a3dddaf-76aa-45e4-bb28-267b3d55df8c" />
      </body>
      <title>January Speaking Schedule</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,1a3dddaf-76aa-45e4-bb28-267b3d55df8c.aspx</guid>
      <link>http://www.davidgiard.com/2010/01/11/JanuarySpeakingSchedule.aspx</link>
      <pubDate>Mon, 11 Jan 2010 13:48:24 GMT</pubDate>
      <description>&lt;p&gt;
Juanary is offically MEF month. I have scheduled "Extending Your Application with
the Managed Extensibility Framework (MEF)" at least 6 times this month. The first
time was last week, when I delivered a Grok Talk at Sogeti that was available via
Live Meeting.
&lt;/p&gt;
&lt;p&gt;
The following presentations will all be about MEF
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Fri Jan 15&amp;nbsp;at 3PM, I will be delivering a vendor session at CodeMash in Sandusky,
OH. 
&lt;li&gt;
Tue Jan 26&amp;nbsp;at Noon, I will deliver a presentation&amp;nbsp;to Financial Corp&amp;nbsp;User
Group&amp;nbsp;in Cincinnati, OH. 
&lt;li&gt;
Tue Jan 26&amp;nbsp;at 6PM, I will present at the&amp;nbsp;Cincinnati .Net User Group&amp;nbsp;in
Mason, OH 
&lt;li&gt;
Wed Jan 27&amp;nbsp;at 6PM, I will present at the&amp;nbsp;Dayton .Net User Group&amp;nbsp;in
Dayton, OH 
&lt;li&gt;
Thu Jan 28 at 6PM, I will present at the Central Ohio .Net User Group in Columbus,
OH&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
In addition, I will deliver two presentations Fri Jan 22 at the State of MI Developer
Briefing&amp;nbsp;in Lansing, MI. 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
At 1PM, I will deliver my MEF presentation (of course).&lt;br&gt;
At 2:30PM, I will present on "Speeding your application with Microsoft Velocity".&lt;br&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1a3dddaf-76aa-45e4-bb28-267b3d55df8c" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,1a3dddaf-76aa-45e4-bb28-267b3d55df8c.aspx</comments>
      <category>Community</category>
      <category>MEF</category>
      <category>Public Speaking</category>
      <category>Velocity</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=08d53007-3ee7-4c6f-b599-2d63bf906ee7</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,08d53007-3ee7-4c6f-b599-2d63bf906ee7.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,08d53007-3ee7-4c6f-b599-2d63bf906ee7.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=08d53007-3ee7-4c6f-b599-2d63bf906ee7</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In Preview 6 of Microsoft's Managed Extensibility Framework (MEF), the framework
changed the rules on matching multiple exports to a single import.
</p>
        <p>
In previous versions of MEF, the attribute syntax was identical whether we were matching
a single item or multiple items to an Import. Both scenarios used the [Import] attribute
to tell MEF to find exports with a matching contract.
</p>
        <p>
For example, if your application is using MEF to match a string variable, based on
a string contract, you would use code similar to the following
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">[Import(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MyMEFString"</span>)] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> SomeString
{ get; set; }</span>
        </pre>
        <p>
This works if MEF finds exactly one matching export string, as in the following code. 
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">[Export(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MyMEFString"</span>)] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> ThatExportedMefString
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"This
string was provided by an MEF contract. It is from an external assembly."</span>;
} }</span>
        </pre>
        <p>
If there is a chance MEF might find multiple Exports that satisfy the above contract,
you would need (in previous versions) to modify the imported type, so that it implements
IEnumerable, as in the following example
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">[Import(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MyMEFString"</span>)]
IEnumerable&lt;<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>&gt;
SomeStringList { get; set; }</span>
        </pre>
        <p>
Beginning with MEF Preview 6, the rule for the attribute becomes more strict. If you
are matching a number of items into an IEnumerable set of items on your import, you
must replace the Import attribute with the ImportMany attribute. In the above example,
the Import declaration becomes
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">[ImportMany(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MyMEFString"</span>)]
IEnumerable&lt;<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>&gt;
SomeStringList { get; set; }</span>
        </pre>
        <p>
The main advantage of this change is that ImportMany will not blow up if MEF finds
no matching export for the contract. Import throws an exception if it cannot
find a matching export. 
</p>
        <p>
Of course, your code will need to handle cases in which there are 0 matches, 1 match,
or many matches when MEF seeks exports to match this contract. In the above example,
that code might look like
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">foreach</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> s <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> SomeStringList)
{ Console.WriteLine(s); }</span>
        </pre>
        <p>
In my opinion, when you are writing an Import and you don't have control over the
Export (for example, if you are allowing third-party vendors to supply the matching
Exports), you should always use the ImportMany attribute. The only time you should
use the Import attribute is if you are only looking for contract matches in assemblies
that you have written and you can guarantee that there will always be exactly one
match.
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=08d53007-3ee7-4c6f-b599-2d63bf906ee7" />
      </body>
      <title>Matching multiple Exports to a single Import in MEF</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,08d53007-3ee7-4c6f-b599-2d63bf906ee7.aspx</guid>
      <link>http://www.davidgiard.com/2009/08/29/MatchingMultipleExportsToASingleImportInMEF.aspx</link>
      <pubDate>Sat, 29 Aug 2009 19:41:51 GMT</pubDate>
      <description>&lt;p&gt;
In&amp;nbsp;Preview 6 of Microsoft's Managed Extensibility Framework (MEF), the framework
changed the rules on matching multiple exports to a single import.
&lt;/p&gt;
&lt;p&gt;
In previous versions of MEF, the attribute syntax was identical&amp;nbsp;whether we were&amp;nbsp;matching
a single item or multiple items to an Import. Both scenarios used the [Import] attribute
to tell MEF to find exports with a matching contract.
&lt;/p&gt;
&lt;p&gt;
For example, if your application is using MEF to match a string variable, based on
a string contract, you would use code similar to the following
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;[Import(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MyMEFString"&lt;/span&gt;)] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; SomeString
{ get; set; }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
This works if MEF finds exactly one matching export string, as in the following code. 
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;[Export(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MyMEFString"&lt;/span&gt;)] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; ThatExportedMefString
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"This
string was provided by an MEF contract. It is from an external assembly."&lt;/span&gt;;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
If there is a chance MEF might find multiple Exports that satisfy the above contract,
you would need (in previous versions) to modify the imported type, so that it implements
IEnumerable, as in the following example
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;[Import(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MyMEFString"&lt;/span&gt;)]
IEnumerable&amp;lt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;&amp;gt;
SomeStringList { get; set; }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Beginning with MEF Preview 6, the rule for the attribute becomes more strict. If you
are matching a number of items into an IEnumerable set of items on your import, you
must replace the Import attribute with the ImportMany attribute. In the above example,
the Import declaration becomes
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;[ImportMany(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MyMEFString"&lt;/span&gt;)]
IEnumerable&amp;lt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;&amp;gt;
SomeStringList { get; set; }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The main advantage of this change is that ImportMany will not blow up if MEF finds
no matching export for the contract. Import&amp;nbsp;throws an exception if it cannot
find a matching export. 
&lt;/p&gt;
&lt;p&gt;
Of course, your code will need to handle cases in which there are 0 matches, 1 match,
or many matches when MEF seeks exports to match this contract. In the above example,
that code might look like
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;foreach&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; s &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; SomeStringList)
{ Console.WriteLine(s); }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
In my opinion, when you are writing an Import and you don't have control over the
Export (for example, if you are allowing third-party vendors to supply the matching
Exports), you should always use the ImportMany attribute. The only time you should
use the Import attribute is if you are only looking for contract matches in assemblies
that you have written and you can guarantee that there will always be exactly one
match.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=08d53007-3ee7-4c6f-b599-2d63bf906ee7" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,08d53007-3ee7-4c6f-b599-2d63bf906ee7.aspx</comments>
      <category>MEF</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=cae61ee8-2d92-4a1b-a1db-35a5964133af</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,cae61ee8-2d92-4a1b-a1db-35a5964133af.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,cae61ee8-2d92-4a1b-a1db-35a5964133af.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=cae61ee8-2d92-4a1b-a1db-35a5964133af</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <img border="0" src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif" />
        </p>
        <p>
          <strong>Episode 43</strong>
        </p>
        <p>
          <a href="http://msmvps.com/blogs/kathleen/" target="_blank">Kathleen Dollard</a> is
the only person I've met who is building a production application using Managed Extensibility
Framework (MEF). In this interview, she describes how to use MEF and shares her vision
of how it will affect the way we architect applications in the future.
</p>
        <p>
          <object id="viddler_723a4eaa" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="348">
            <param name="_cx" value="11562" />
            <param name="_cy" value="9207" />
            <param name="FlashVars" value="" />
            <param name="Movie" value="http://www.viddler.com/simple/723a4eaa/" />
            <param name="Src" value="http://www.viddler.com/simple/723a4eaa/" />
            <param name="WMode" value="Window" />
            <param name="Play" value="-1" />
            <param name="Loop" value="-1" />
            <param name="Quality" value="High" />
            <param name="SAlign" value="LT" />
            <param name="Menu" value="-1" />
            <param name="Base" value="" />
            <param name="AllowScriptAccess" value="always" />
            <param name="Scale" value="ShowAll" />
            <param name="DeviceFont" value="0" />
            <param name="EmbedMovie" value="0" />
            <param name="BGColor" value="" />
            <param name="SWRemote" value="" />
            <param name="MovieData" value="" />
            <param name="SeamlessTabbing" value="1" />
            <param name="Profile" value="0" />
            <param name="ProfileAddress" value="" />
            <param name="ProfilePort" value="0" />
            <param name="AllowNetworking" value="all" />
            <param name="AllowFullScreen" value="true" />
            <embed src="http://www.viddler.com/simple/723a4eaa/" width="437" height="348" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_723a4eaa">
            </embed>
          </object>
        </p>
        <p>
          <font size="1">17 mins, 37 secs</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=cae61ee8-2d92-4a1b-a1db-35a5964133af" />
      </body>
      <title>Kathleen Dollard on MEF</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,cae61ee8-2d92-4a1b-a1db-35a5964133af.aspx</guid>
      <link>http://www.davidgiard.com/2009/08/24/KathleenDollardOnMEF.aspx</link>
      <pubDate>Mon, 24 Aug 2009 03:24:28 GMT</pubDate>
      <description>&lt;p&gt;
&lt;img border=0 src="http://www.davidgiard.com/content/binary/TechnologyAndFriends.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Episode 43&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msmvps.com/blogs/kathleen/" target=_blank&gt;Kathleen Dollard&lt;/a&gt; is
the only person I've met who is building a production application using Managed Extensibility
Framework (MEF). In this interview, she describes how to use MEF and shares her vision
of how it will affect the way we architect applications in the future.
&lt;/p&gt;
&lt;p&gt;
&lt;object id=viddler_723a4eaa classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=437 height=348&gt;
&lt;param name="_cx" value="11562"&gt;
&lt;param name="_cy" value="9207"&gt;
&lt;param name="FlashVars" value=""&gt;
&lt;param name="Movie" value="http://www.viddler.com/simple/723a4eaa/"&gt;
&lt;param name="Src" value="http://www.viddler.com/simple/723a4eaa/"&gt;
&lt;param name="WMode" value="Window"&gt;
&lt;param name="Play" value="-1"&gt;
&lt;param name="Loop" value="-1"&gt;
&lt;param name="Quality" value="High"&gt;
&lt;param name="SAlign" value="LT"&gt;
&lt;param name="Menu" value="-1"&gt;
&lt;param name="Base" value=""&gt;
&lt;param name="AllowScriptAccess" value="always"&gt;
&lt;param name="Scale" value="ShowAll"&gt;
&lt;param name="DeviceFont" value="0"&gt;
&lt;param name="EmbedMovie" value="0"&gt;
&lt;param name="BGColor" value=""&gt;
&lt;param name="SWRemote" value=""&gt;
&lt;param name="MovieData" value=""&gt;
&lt;param name="SeamlessTabbing" value="1"&gt;
&lt;param name="Profile" value="0"&gt;
&lt;param name="ProfileAddress" value=""&gt;
&lt;param name="ProfilePort" value="0"&gt;
&lt;param name="AllowNetworking" value="all"&gt;
&lt;param name="AllowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/simple/723a4eaa/" width="437" height="348" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_723a4eaa"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;17 mins, 37 secs&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=cae61ee8-2d92-4a1b-a1db-35a5964133af" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,cae61ee8-2d92-4a1b-a1db-35a5964133af.aspx</comments>
      <category>Interviews</category>
      <category>MEF</category>
      <category>Technology and Friends</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=9704283b-9acc-4033-aae4-98de774508f2</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,9704283b-9acc-4033-aae4-98de774508f2.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,9704283b-9acc-4033-aae4-98de774508f2.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9704283b-9acc-4033-aae4-98de774508f2</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
        <p>
CodeStock 2009 is in the books. I didn't attend last year, but this year, the Knoxville
developer conference expanded to two days and more than doubled the number of attendees.
</p>
        <p>
This conferences ranks high on the important value-per-dollar scale. As a speaker,
the $25 conference fee was waived; I shared a ride to Tennessee with five other attendees;
and I used the last of my Marriott points for the hotel. All told, I had 2 days of
great content for under a hundred bucks in meals and gas. By far, my biggest cost
was the two vacation days I had to spend in order to attend.
</p>
        <p>
I saw some very good sessions and met a lot of bright people. In one spontaneous open
space, I solicited feedback on the layout of my blog. As a result, I've removed some
unneeded links, moved the RSS feed to the top of the main page and enabled Google
analytics.
</p>
        <p>
I even had a chance to <a href="http://www.davidgiard.com/2009/07/01/MikeNeelOnCodeStock2009.aspx">talk
with CodeStock organizer Mike Neel</a> near the end of the conference. 
</p>
        <p>
I presented a session on Microsoft Managed Extensibility Framework. It was well-received
and many in the audience were actively engaged, asking questions that indicated they
grasped all the concepts I was trying to communicate.  
</p>
        <p>
You can download the slides for my MEF presentation from the link below.
</p>
        <p>
          <iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 240px; PADDING-RIGHT: 0px; HEIGHT: 26px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight="0" src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedrow.aspx/.Public/CodeStock2009/Managed%20Extensibility%20Framework%20%7C5Codestock%202009%7C6.pptx" frameborder="0" marginwidth="0" scrolling="no">
          </iframe>
        </p>
        <p>
The content and samples of this presentation are covered in the articles below.
</p>
        <ul>
          <li>
            <a href="http://www.davidgiard.com/2009/05/30/WhyMEF.aspx">Why MEF?</a>
          </li>
          <li>
            <a href="http://www.davidgiard.com/2009/06/10/SimpleContractsInTheMicrosoftManagedExtensibilityFramework.aspx">Simple
Contracts in the Microsoft Managed Extensibility Framework</a>
          </li>
          <li>
            <a href="http://www.davidgiard.com/2009/06/13/InterfaceContractsInMEF.aspx">Interface
Contracts in MEF</a>
          </li>
          <li>
            <a href="http://www.davidgiard.com/2009/06/15/MetadataInMEF.aspx">Metadata in MEF</a>
            <br />
          </li>
        </ul>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=9704283b-9acc-4033-aae4-98de774508f2" />
      </body>
      <title>CodesStock 2009 recap</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,9704283b-9acc-4033-aae4-98de774508f2.aspx</guid>
      <link>http://www.davidgiard.com/2009/07/03/CodesStock2009Recap.aspx</link>
      <pubDate>Fri, 03 Jul 2009 12:59:07 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
CodeStock 2009 is in the books. I didn't attend last year, but this year, the Knoxville
developer conference expanded to two days and more than doubled the number of attendees.
&lt;/p&gt;
&lt;p&gt;
This conferences ranks high on the important value-per-dollar scale. As a speaker,
the $25 conference fee was waived; I shared a ride to Tennessee with five other attendees;
and I used the last of my Marriott points for the hotel. All told, I had 2 days of
great content for under a hundred bucks in meals and gas. By far, my biggest cost
was the two vacation days I had to spend in order to attend.
&lt;/p&gt;
&lt;p&gt;
I saw some very good sessions and met a lot of bright people. In one spontaneous open
space, I solicited feedback on the layout of my blog. As a result, I've removed some
unneeded links, moved the RSS feed to the top of the main page and enabled Google
analytics.
&lt;/p&gt;
&lt;p&gt;
I even&amp;nbsp;had a chance to &lt;a href="http://www.davidgiard.com/2009/07/01/MikeNeelOnCodeStock2009.aspx"&gt;talk
with CodeStock organizer Mike Neel&lt;/a&gt; near the end of the conference. 
&lt;/p&gt;
&lt;p&gt;
I presented a session on Microsoft Managed Extensibility Framework. It was well-received
and many in the audience were actively engaged, asking questions that indicated they
grasped all the concepts I was trying to communicate.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
You can download the slides for my MEF presentation from the link below.
&lt;/p&gt;
&lt;p&gt;
&lt;iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 240px; PADDING-RIGHT: 0px; HEIGHT: 26px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight=0 src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedrow.aspx/.Public/CodeStock2009/Managed%20Extensibility%20Framework%20%7C5Codestock%202009%7C6.pptx" frameborder=0 marginwidth=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;
The content and samples of this presentation are covered in the articles below.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.davidgiard.com/2009/05/30/WhyMEF.aspx"&gt;Why MEF?&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.davidgiard.com/2009/06/10/SimpleContractsInTheMicrosoftManagedExtensibilityFramework.aspx"&gt;Simple
Contracts in the Microsoft Managed Extensibility Framework&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.davidgiard.com/2009/06/13/InterfaceContractsInMEF.aspx"&gt;Interface
Contracts in MEF&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://www.davidgiard.com/2009/06/15/MetadataInMEF.aspx"&gt;Metadata in MEF&lt;/a&gt;
&lt;br&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=9704283b-9acc-4033-aae4-98de774508f2" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,9704283b-9acc-4033-aae4-98de774508f2.aspx</comments>
      <category>MEF</category>
      <category>Public Speaking</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=264467f9-2198-4b09-b4cc-3ad1c18097c5</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,264467f9-2198-4b09-b4cc-3ad1c18097c5.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,264467f9-2198-4b09-b4cc-3ad1c18097c5.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=264467f9-2198-4b09-b4cc-3ad1c18097c5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In previous articles, I showed how to create a simple <a href="http://www.davidgiard.com/2009/06/10/SimpleContractsInTheMicrosoftManagedExtensibilityFramework.aspx">MEF
contract based on a string</a> and a <a href="http://www.davidgiard.com/2009/06/13/InterfaceContractsInMEF.aspx">contract
based on an Interface</a>.
</p>
        <p>
Recall that MEF uses a contract that matches Import and Export components at runtime. 
Contracts are defined by Import and Export attributes applied to declarations and
definitions, respectively.
</p>
        <p>
In this article, I'll show how to add metadata to your export data and to read that
metadata at runtime.
</p>
        <p>
We'll start with the sample created in my <a href="http://www.davidgiard.com/2009/06/13/InterfaceContractsInMEF.aspx">article
about Interfaces</a>.  In this sample, we created three projects:
</p>
        <ul>
          <li>
            <em>MEFInterface </em>contains the <em>IToDo </em>interface. 
</li>
          <li>
            <em>MEFConsoleApp1 </em>is our console application.  It contains the Import property
based on the <em>IToDo </em>interface. 
</li>
          <li>
            <em>MEFComponent1 </em>is a class library containing an exported property implementing
the <em>IToDo </em>interface.</li>
        </ul>
        <p>
We can add metadata to an Export with the <em>ExportMetaData</em> attribute. 
The <em>ExportMetaData </em>attribute accepts two parameters: the name and the value
of metadata applied to that export.  When MEF imports this export, the metadata
is imported as well and is accessible from code.  Below is an Export from our
sample with the ExportMetaData attribute applied.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Export(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(IToDo))]
[ExportMetadata(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Priority"</span>,
2)] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> FirstTask
: IToDo { ... } </span>
        </pre>
        <p>
We apply a similar attribute to the other Export in MEFComponent1
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Export(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(IToDo))]
[ExportMetadata(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Priority"</span>,
1)] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> ImportantTask
: IToDo { ... } </span>
        </pre>
        <p>
          <em>MEFConsoleApp1 </em>contained an Import that declared a collection of <em>IToDo </em>objects.
To access the metadata of this collection, we should change the declaration to an
ExportCollection. An ExportCollection implements the <em>IEnumerable </em>interface,
but also exposes MEF metadata.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Import(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(IToDo))] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span> ExportCollection&lt;IToDo&gt;
ToDoList { get; set; } </span>
        </pre>
        <p>
The code telling MEF to match up contracts remains the same; but the code to access
the data and metadata changes to loop through the ExportCollection, as shown below.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">foreach</span> (Export&lt;IToDo&gt;
exTd <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> ToDoList)
{ IToDo td <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> exTd.GetExportedObject();
Console.WriteLine(td.TaskName); <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> priority <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Convert.ToInt32(exTd.Metadata[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Priority"</span>]);
Console.WriteLine(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Priority="</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> priority.ToString());
} </span>
        </pre>
        <p>
In the above code, exTd is an Export object.  The Export object contains not
only the IToDo object we imported (via the GetExportedObject method); it also allows
us to retrieve metadata.  Since metadata is a set of name-value pairs, we can
retrieve a value by passing the name to the Metadata collection.  In this case,
we pass get the value of Metadata["Priority"].
</p>
        <p>
In this article, we showed how to apply metadata to an MEF Export and how to retrieve
that metadata at runtime.
</p>
        <p>
Code: <a href="http://www.davidgiard.com/content/binary/MEFDemo3.zip">MEFDemo3.zip
(574.93 KB)</a></p>
        <p>
          <font size="1">Note: The code in this article uses MEF CTP 5.</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=264467f9-2198-4b09-b4cc-3ad1c18097c5" />
      </body>
      <title>Metadata in MEF</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,264467f9-2198-4b09-b4cc-3ad1c18097c5.aspx</guid>
      <link>http://www.davidgiard.com/2009/06/15/MetadataInMEF.aspx</link>
      <pubDate>Mon, 15 Jun 2009 11:10:38 GMT</pubDate>
      <description>&lt;p&gt;
In previous articles, I showed how to create a simple &lt;a href="http://www.davidgiard.com/2009/06/10/SimpleContractsInTheMicrosoftManagedExtensibilityFramework.aspx"&gt;MEF
contract based on a string&lt;/a&gt; and a &lt;a href="http://www.davidgiard.com/2009/06/13/InterfaceContractsInMEF.aspx"&gt;contract
based on an Interface&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Recall that MEF uses a contract that matches Import and Export components at runtime.&amp;nbsp;
Contracts are defined by Import and Export attributes applied to declarations and
definitions, respectively.
&lt;/p&gt;
&lt;p&gt;
In this article, I'll show how to add metadata to your export data and to read that
metadata at runtime.
&lt;/p&gt;
&lt;p&gt;
We'll start with the sample created in&amp;nbsp;my &lt;a href="http://www.davidgiard.com/2009/06/13/InterfaceContractsInMEF.aspx"&gt;article
about Interfaces&lt;/a&gt;.&amp;nbsp; In this sample, we created three projects:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;MEFInterface &lt;/em&gt;contains the &lt;em&gt;IToDo &lt;/em&gt;interface. 
&lt;li&gt;
&lt;em&gt;MEFConsoleApp1 &lt;/em&gt;is our console application.&amp;nbsp; It contains the Import property
based on the &lt;em&gt;IToDo &lt;/em&gt;interface. 
&lt;li&gt;
&lt;em&gt;MEFComponent1 &lt;/em&gt;is a class library containing an exported property implementing
the &lt;em&gt;IToDo &lt;/em&gt;interface.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We can add metadata to an Export with the &lt;em&gt;ExportMetaData&lt;/em&gt; attribute.&amp;nbsp;
The &lt;em&gt;ExportMetaData &lt;/em&gt;attribute accepts two parameters: the name and the value
of metadata applied to that export.&amp;nbsp; When MEF imports this export, the metadata
is imported as well and is accessible from code.&amp;nbsp; Below is an Export from our
sample with the ExportMetaData attribute applied.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Export(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(IToDo))]
[ExportMetadata(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Priority"&lt;/span&gt;,
2)] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; FirstTask
: IToDo { ... } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
We apply a similar attribute to the other Export in MEFComponent1
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Export(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(IToDo))]
[ExportMetadata(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Priority"&lt;/span&gt;,
1)] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; ImportantTask
: IToDo { ... } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;em&gt;MEFConsoleApp1 &lt;/em&gt;contained an Import that declared a collection of &lt;em&gt;IToDo &lt;/em&gt;objects.
To access the metadata of this collection, we should change the declaration to an
ExportCollection. An ExportCollection implements the &lt;em&gt;IEnumerable &lt;/em&gt;interface,
but also exposes MEF metadata.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Import(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(IToDo))] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; ExportCollection&amp;lt;IToDo&amp;gt;
ToDoList { get; set; } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The code telling MEF to match up contracts remains the same; but the code to access
the data and metadata changes to loop through the ExportCollection, as shown below.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;foreach&lt;/span&gt; (Export&amp;lt;IToDo&amp;gt;
exTd &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; ToDoList)
{ IToDo td &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; exTd.GetExportedObject();
Console.WriteLine(td.TaskName); &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; priority &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Convert.ToInt32(exTd.Metadata[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Priority"&lt;/span&gt;]);
Console.WriteLine(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Priority="&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; priority.ToString());
} &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
In the above code, exTd is an Export object.&amp;nbsp; The Export object contains not
only the IToDo object we imported (via the GetExportedObject method); it also allows
us to retrieve metadata.&amp;nbsp; Since metadata is a set of name-value pairs, we can
retrieve a value by passing the name to the Metadata collection.&amp;nbsp; In this case,
we pass get the value of Metadata["Priority"].
&lt;/p&gt;
&lt;p&gt;
In this article, we showed how to apply metadata to an MEF Export and how to retrieve
that metadata at runtime.
&lt;/p&gt;
&lt;p&gt;
Code: &lt;a href="http://www.davidgiard.com/content/binary/MEFDemo3.zip"&gt;MEFDemo3.zip
(574.93 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;Note: The code in this article uses MEF CTP 5.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=264467f9-2198-4b09-b4cc-3ad1c18097c5" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,264467f9-2198-4b09-b4cc-3ad1c18097c5.aspx</comments>
      <category>MEF</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=1e868cc8-db36-4a50-80a3-21d294cbf500</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,1e868cc8-db36-4a50-80a3-21d294cbf500.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,1e868cc8-db36-4a50-80a3-21d294cbf500.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1e868cc8-db36-4a50-80a3-21d294cbf500</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In <a href="http://www.davidgiard.com/2009/06/10/SimpleContractsInTheMicrosoftManagedExtensibilityFramework.aspx">my
last article</a>, I showed how to create a Managed Extensibility Framework (MEF) contract
using the [Import] and [Export] attributes.  The code in that article created
a contract based on a string and imported only a string variable.  I chose that
sample because it was the simplest I could think of to illustrate the concepts of
a contract.  But if all you are doing is swapping strings at runtime, there are
simpler ways to accomplish this than MEF.
</p>
        <p>
In this article, we will create a contract based on an interface.  Interfaces
describe public properties and methods of a class without providing any implementation
of those properties and methods.  This gives developers the flexibility to decide
later which class to instantiate.  With MEF, that flexibility is increased even
more because developers do not need to set a reference to classes at compile time.
</p>
        <p>
Recall that MEF uses a contract that matches Import and Export components at runtime. 
Contracts are defined by Import and Export attributes.
</p>
        <p>
In our sample, we create three projects:
</p>
        <ul>
          <li>
            <em>MEFInterface </em>contains the IToDo interface. 
</li>
          <li>
            <em>MEFConsoleApp1 </em>is our console application.  It contains the Import property
based on the <em>IToDo </em>interface. 
</li>
          <li>
            <em>MEFComponent1 </em>is a class library containing an exported property implementing
the <em>IToDo </em>interface.</li>
        </ul>
        <p>
          <em>MEFConsoleApp1 </em>and <em>MEFComponent1 </em>each have a reference to <em>MEFInterface </em>because
each contains a class that implements the <em>IToDo </em>interface.  However, <em>MEFConsoleApp1 </em>does
not contain a reference to <em>MEFComponent1</em>, even though the console app will
consume classes in the class library.  An MEF contract replaces the tight coupling
of a typical application.
</p>
        <p>
          <strong>Creating the Contract </strong>
        </p>
        <p>
To accomplish this, we do the following<br />
1. Create the IToDo interface in the MEFInterface project.  This interface defines
two properties: <em>TaskName </em>and <em>HoursRequired</em>, as shown below<br /></p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">interface</span> IToDo
{ <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> TaskName
{ get; } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">double</span> HoursRequired
{ get; } } </span>
        </pre>
        <p>
          <br />
2. In the console application, declare a variable of type IToDo and decorate this
variable with the Import attribute.  The Import attribute accepts a parameter
that defines the contract.  Assign the contract type of the import attribute
as TypeOf (IToDo) as shown below
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Import(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(IToDo))] <font size="2"><p></p></font><font color="#0000ff" size="2"><font color="#0000ff" size="2"> public</font></font><font size="2"></font><font color="#2b91af" size="2"><font color="#2b91af" size="2">IToDo</font></font><font size="2"> MyTask
{</font><font color="#0000ff" size="2"><font color="#0000ff" size="2">get</font></font><font size="2">; </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">set</font></font><font size="2">;}
</font></span>
        </pre>
        <p>
3. In the MEFComponent1 project, create a class that implements IToDo.  Return
a value from each property's getter and decorate this class with the Export
attribute.  Assign the contract type parameter as TypeOf(IToDo).  We now
have a contract because we have an import and an export with the same contract parameter. 
MEF will match these up when we tall it where to compose its parts.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Export(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(IToDo))] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> FirstTask
: IToDo { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> TaskName
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Get
out of bed"</span>; } } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">double</span> HoursRequired
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> .10;
} } } </span>
        </pre>
        <p>
4. As in the code from the last article, we must tell MEF where to find all the parts
to compose.  Add the following code to the <em>MEFConsoleApp1</em>.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> folderToWatch <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><br />
System.Configuration.ConfigurationSettings.AppSettings[<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MEFExportFolder"</span>];<br />
var catalog <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> DirectoryCatalog(folderToWatch);
var container <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> CompositionContainer(catalog);
var batch <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> CompositionBatch();
batch.AddPart(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">this</span>);
container.Compose(batch); </span>
        </pre>
        <p>
5. The above code gets the folder location from App.Config file, so you will need
to add to the MEFConsoleApp1 project an application configration file with the following
contents. (Set the directory to the location of the compiled DLL for the <em>MEFComponent1 </em>project).
</p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">&lt;?xml
version=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"1.0"</span> encoding=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"utf-8"</span> ?&gt;<br />
&lt;configuration&gt;<br />
  &lt;appSettings&gt;<br />
    &lt;add key=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MEFExportFolder"</span><br />
         value=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"C:\Development\MEF\DGCode\MEFDemo2\MEFComponent1\bin\Debug"</span> /&gt;<br />
  &lt;/appSettings&gt;<br />
&lt;/configuration&gt;</span>
        </p>
        <p>
6. Finally, add code in <em>MEFConsoleApp1</em> to output values of our variable.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> Console.WriteLine<br />
(<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Format<br />
(<br /><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"It
takes {0} hours to do the task: {1}."</span>, 
<br />
MyTask.HoursRequired, 
<br />
MyTask.TaskName<br />
)<br />
); </span>
        </pre>
        <p>
          <strong>What if there are Multiple Exports matching an Import? </strong>
        </p>
        <p>
In this case, MEF was able to match a single IToDo Export with a single IToDo import.
But what would happen if MEF found two Exports to match just one import? 
</p>
        <p>
In our example, we might add to <em>MEFComponent1 </em>a second exportd class that
implements IToDo.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Export(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(IToDo))] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> ImportantTask
: IToDo { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> TaskName
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Make
the donuts"</span>; } } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">double</span> HoursRequired
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span> .25;
} } </span>
        </pre>
        <p>
Which Export would MEF choose to match the Import?  Both satisfy the contract. 
The answer is that MEF would choose to throw an exception.  If we can't be sure
of how many Exports MEF will find to match our Import contract, we should replace
our IToDo declaration with an collection of IToDo objects for the Import,
as shown below.
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Import(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">typeof</span>(IToDo))] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span> IEnumerable&lt;IToDo&gt;
ToDoList { get; set; } </span>
        </pre>
        <p>
Then, we can loop through this collection and output all the properties:
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">foreach</span> (var
td <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> ToDoList)
{ Console.WriteLine<br />
(<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Format<br />
(<br /><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"It
takes {0} hours to do the task: {1}."</span>, 
<br />
td.HoursRequired, 
<br />
td.TaskName<br />
)<br />
); } </span>
        </pre>
        <p>
In this article, we showed how to create an MEF contract based on an interface
and how to handle mutliple exports for a single import in an MEF contract.
</p>
        <p>
Code: <a href="http://www.davidgiard.com/content/binary/MEFDemo2.zip">MEFDemo2.zip
(574.36 KB)</a></p>
        <p>
          <font size="1">Note: The code in this article uses MEF CTP 5.</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1e868cc8-db36-4a50-80a3-21d294cbf500" />
      </body>
      <title>Interface Contracts in MEF</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,1e868cc8-db36-4a50-80a3-21d294cbf500.aspx</guid>
      <link>http://www.davidgiard.com/2009/06/13/InterfaceContractsInMEF.aspx</link>
      <pubDate>Sat, 13 Jun 2009 03:19:00 GMT</pubDate>
      <description>&lt;p&gt;
In &lt;a href="http://www.davidgiard.com/2009/06/10/SimpleContractsInTheMicrosoftManagedExtensibilityFramework.aspx"&gt;my
last article&lt;/a&gt;, I showed how to create a Managed Extensibility Framework (MEF) contract
using the [Import] and [Export] attributes.&amp;nbsp; The code in that article created
a contract based on a string and imported only a string variable.&amp;nbsp; I chose that
sample because it was the simplest I could think of to illustrate the concepts of
a contract.&amp;nbsp; But if all you are doing is swapping strings at runtime, there are
simpler ways to accomplish this than MEF.
&lt;/p&gt;
&lt;p&gt;
In this article, we will create a contract based on an interface.&amp;nbsp; Interfaces
describe public properties and methods of a class without providing any implementation
of those properties and methods.&amp;nbsp; This gives developers the flexibility to decide
later which class to instantiate.&amp;nbsp; With MEF, that flexibility is increased even
more because developers do not need to set a reference to classes at compile time.
&lt;/p&gt;
&lt;p&gt;
Recall that MEF uses a contract that matches Import and Export components at runtime.&amp;nbsp;
Contracts are defined by Import and Export attributes.
&lt;/p&gt;
&lt;p&gt;
In our sample, we create three projects:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;MEFInterface &lt;/em&gt;contains the IToDo interface. 
&lt;li&gt;
&lt;em&gt;MEFConsoleApp1 &lt;/em&gt;is our console application.&amp;nbsp; It contains the Import property
based on the &lt;em&gt;IToDo &lt;/em&gt;interface. 
&lt;li&gt;
&lt;em&gt;MEFComponent1 &lt;/em&gt;is a class library containing an exported property implementing
the &lt;em&gt;IToDo &lt;/em&gt;interface.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;em&gt;MEFConsoleApp1 &lt;/em&gt;and &lt;em&gt;MEFComponent1 &lt;/em&gt;each have a reference to &lt;em&gt;MEFInterface &lt;/em&gt;because
each contains a class that implements the &lt;em&gt;IToDo &lt;/em&gt;interface.&amp;nbsp; However, &lt;em&gt;MEFConsoleApp1 &lt;/em&gt;does
not contain a reference to &lt;em&gt;MEFComponent1&lt;/em&gt;, even though the console app will
consume classes in the class library.&amp;nbsp; An MEF contract replaces the tight coupling
of a typical application.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Creating the Contract&amp;nbsp;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
To accomplish this, we do the following&lt;br&gt;
1. Create the IToDo interface in the MEFInterface project.&amp;nbsp; This interface defines
two properties: &lt;em&gt;TaskName &lt;/em&gt;and &lt;em&gt;HoursRequired&lt;/em&gt;, as shown below&lt;br&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;interface&lt;/span&gt; IToDo
{ &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; TaskName
{ get; } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;double&lt;/span&gt; HoursRequired
{ get; } } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;br&gt;
2. In the console application, declare a variable of type IToDo and decorate this
variable with the Import attribute.&amp;nbsp; The Import attribute accepts a parameter
that defines the contract.&amp;nbsp; Assign the contract type of the import attribute
as TypeOf (IToDo) as shown below
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Import(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(IToDo))] &lt;font size=2&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt; public&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; &lt;/font&gt;&lt;font color=#2b91af size=2&gt;&lt;font color=#2b91af size=2&gt;IToDo&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; MyTask
{&lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;get&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt;set&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt;;}&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
3. In the MEFComponent1 project, create a class that implements IToDo.&amp;nbsp; Return
a value from&amp;nbsp;each property's getter&amp;nbsp;and decorate this class with the Export
attribute.&amp;nbsp; Assign the contract type parameter as TypeOf(IToDo).&amp;nbsp; We now
have a contract because we have an import and an export with the same contract parameter.&amp;nbsp;
MEF will match these up when we tall it where to compose its parts.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Export(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(IToDo))] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; FirstTask
: IToDo { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; TaskName
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Get
out of bed"&lt;/span&gt;; } } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;double&lt;/span&gt; HoursRequired
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; .10;
} } } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
4. As in the code from the last article, we must tell MEF where to find all the parts
to compose.&amp;nbsp; Add the following code to the &lt;em&gt;MEFConsoleApp1&lt;/em&gt;.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; folderToWatch &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 
&lt;br&gt;
System.Configuration.ConfigurationSettings.AppSettings[&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MEFExportFolder"&lt;/span&gt;];&lt;br&gt;
var catalog &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; DirectoryCatalog(folderToWatch);
var container &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; CompositionContainer(catalog);
var batch &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; CompositionBatch();
batch.AddPart(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;this&lt;/span&gt;);
container.Compose(batch); &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
5. The above code gets the folder location from App.Config file, so you will need
to add to the MEFConsoleApp1 project an application configration file with the following
contents. (Set the directory to the location of the compiled DLL for the &lt;em&gt;MEFComponent1 &lt;/em&gt;project).
&lt;/p&gt;
&lt;p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;lt;?xml
version=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"utf-8"&lt;/span&gt; ?&amp;gt;&lt;br&gt;
&amp;lt;configuration&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;appSettings&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add key=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MEFExportFolder"&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"C:\Development\MEF\DGCode\MEFDemo2\MEFComponent1\bin\Debug"&lt;/span&gt; /&amp;gt;&lt;br&gt;
&amp;nbsp; &amp;lt;/appSettings&amp;gt;&lt;br&gt;
&amp;lt;/configuration&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
6. Finally,&amp;nbsp;add code in &lt;em&gt;MEFConsoleApp1&lt;/em&gt; to output values of our variable.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; Console.WriteLine&lt;br&gt;
(&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Format&lt;br&gt;
(&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"It
takes {0} hours to do the task: {1}."&lt;/span&gt;, 
&lt;br&gt;
MyTask.HoursRequired, 
&lt;br&gt;
MyTask.TaskName&lt;br&gt;
)&lt;br&gt;
); &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;strong&gt;What if there are Multiple Exports&amp;nbsp;matching an Import?&amp;nbsp;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In this case, MEF was able to match a single IToDo Export with a single IToDo import.
But what would happen if MEF found two Exports to match just one import?&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
In our example, we might add to &lt;em&gt;MEFComponent1 &lt;/em&gt;a second exportd class that
implements IToDo.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Export(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(IToDo))] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; ImportantTask
: IToDo { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; TaskName
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Make
the donuts"&lt;/span&gt;; } } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;double&lt;/span&gt; HoursRequired
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; .25;
} } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Which Export would&amp;nbsp;MEF choose to match the Import?&amp;nbsp; Both satisfy the contract.&amp;nbsp;
The answer is that MEF would choose to throw an exception.&amp;nbsp; If we can't be sure
of how many Exports MEF will find to match our Import contract, we should replace
our IToDo declaration with an&amp;nbsp;collection of IToDo&amp;nbsp;objects for the Import,
as shown below.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Import(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;typeof&lt;/span&gt;(IToDo))] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; IEnumerable&amp;lt;IToDo&amp;gt;
ToDoList { get; set; } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Then, we can loop through this collection and output all the properties:
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;foreach&lt;/span&gt; (var
td &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; ToDoList)
{ Console.WriteLine&lt;br&gt;
(&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Format&lt;br&gt;
(&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"It
takes {0} hours to do the task: {1}."&lt;/span&gt;, 
&lt;br&gt;
td.HoursRequired, 
&lt;br&gt;
td.TaskName&lt;br&gt;
)&lt;br&gt;
); } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
In this article, we showed how to create an MEF&amp;nbsp;contract based on an interface
and how to handle mutliple exports for a single import in an MEF&amp;nbsp;contract.
&lt;/p&gt;
&lt;p&gt;
Code: &lt;a href="http://www.davidgiard.com/content/binary/MEFDemo2.zip"&gt;MEFDemo2.zip
(574.36 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;Note: The code in this article uses MEF CTP 5.&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=1e868cc8-db36-4a50-80a3-21d294cbf500" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,1e868cc8-db36-4a50-80a3-21d294cbf500.aspx</comments>
      <category>MEF</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft Managed Extensibility Framework (MEF) is a framework for building applications
composed of parts.  By constructing an application of parts, any part can be
replaced at runtime.  
</p>
        <p>
In order to use this framework in your project, you will need to set reference to
System.ComponentModel.Composition.dll (which you can download from <a href="http://codeplex.com/MEF">http://codeplex.com/MEF</a>)
and add the following statements to the top of any module with MEF code or attributes
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.ComponentModel.Composition;<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">using</span> System.ComponentModel.Composition.Hosting; </span>
        </pre>
        <p>
The composition of MEF parts is very loosely coupled.  Coupling occurs using
contracts.  A contract consists of an Import and one or more Exports. 
</p>
        <p>
An Import is a place in your application that defines a variable but does not explicitly
state how that variable is implemented.  Instead, a declaration is decorated
with the [Import] attribute.  A parameter of the [Import] attribute describes
the implementation that the variable is seeking.  This parameter can be a string,
a type or an interface.  When MEF encounters an Import, it looks for an Export
that matches the Import's contract parameter.
</p>
        <p>
An Export is a class decorated with the [Export] attribute. This attribute tells MEF
that the class is available to satisfy any matching Import request.  Just as
with the [Import] attribute, the [Export] attribute accepts a parameter that is a
string, a type or an interface.
</p>
        <p>
For example, the following variable declaration
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Import(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MyMEFString"</span>)] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> SomeString
{ get; set; } </span>
        </pre>
        <p>
          <br />
defines an import with a contract "MyMEFString". That contract is satisfied by the
following export
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> [Export(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"MyMEFString"</span>)] <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> ThatExportedMefString
{ get { <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">return</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"This
string was provided by an MEF contract. It is from an external assembly."</span>;
} } </span>
        </pre>
        <p>
Simply declaring this contract isn't enough.  We need to tell MEF to match up
the imports and exports.  The following steps are necessary for MEF to do its
thing<br />
1. Create a catalog.  A catalog tells MEF where to find the Imports and Exports.<br />
2. Create a container that uses the catalog.<br />
3. Create a batch and call the Compose method of that batch.  The Compose method
tells MEF to find the Imports and Exports that make up each contract and match them
up.
</p>
        <p>
If you want to compose parts that all exist in the currently executing assembly, this
is done with the following code
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"> var
catalog <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> AssemblyCatalog(Assembly.GetExecutingAssembly());<br />
var container <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> CompositionContainer(catalog);<br />
var batch <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> CompositionBatch();<br />
batch.AddPart(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">this</span>);<br />
container.Compose(batch); </span>
        </pre>
        <p>
The code above assumes that the contract's Exports and Imports are in the same project.  
</p>
        <p>
Notice the first line of code, in which we declare a variable named 'catalog'. 
This line instantiates a Catalog object.  A Catalog object defines where MEF
looks for parts.  MEF supports the following types of Catalogs 
</p>
        <ul>
          <li>
An <strong>Assembly Catalog </strong>retrieves MEF components compiled into a given
assembly. 
</li>
          <li>
A <strong>Directory Catalog </strong>retrieves all MEF components in all assemblies
in a given directory. 
</li>
          <li>
An <strong>Aggregating Catalog</strong> is used when you want to retrieve MEF components
from multiple places - for example, from a specific assembly and from a directory;
or from two different directories.</li>
        </ul>
        <p>
Of course it doesn't make much sense to go to the trouble of using a loosely-coupled
framework like MEF and getting your parts from the current assembly. In fact, it often
doesn't make sense to get parts from an assembly that is known at design time. 
If we know the assembly name and location, we might as well set an explicit references
to it. 
</p>
        <p>
A more likely scenario is to import all MEF assemblies found in a specific folder.
To do this, we use a Directory Catalog.  We replace the declaration/initialization
of the catalog with the following line
</p>
        <pre>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> folderToWatch <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">@"C:\Development\MEF\DGCode\MEFDemo1\MEFComponent1\bin\Debug"</span>;<br />
var catalog <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> DirectoryCatalog(folderToWatch); </span>
        </pre>
        <p>
By setting our catalog to a DirectoryCatalog, we tell MEF to search for imports in
all assemblies found in a well-known folder.  We can just drop DLLs into this
folder and MEF will find them and use them at runtime, even if our projects do not
set a reference to them.
</p>
        <p>
The <em>MEFDemo1 </em>solution is a very simple sample that uses this code.  
</p>
        <p>
In <em>MEFDemo1</em>, a console application declares a string variable named "SomeString"
which is decorated with the Import attribute and defined by the contract "MyMEFString".  
</p>
        <p>
At runtime, MEF determines the The value of SomeString by searching for the Export
half of the contract.  It finds it in ThatExportedMefString variable, declared
in the <em>Class1 </em>class of the <em>MEFComponent1 </em>project.  MEF knows
to look here because we pointed a DirectoryCatalog at the folder where <em>MEFComponent1.dll </em>is
compiled.  (If you copy this solution to a different directory, you will need
to change the path defined in <em>folderToWatch</em> and recompile the <em>MEFComponent1 </em>project.
In a real-world application, we would probably pull the folder name from a configuration
file or otherwise set it at runtime to make it even more flexible.)  
</p>
        <p>
The important point is that we don't need to set any references between these projects
in order for them to communicate.  The contract and MEF take care of this for
us.
</p>
        <p>
In this article, we showed a very simple MEF contract, based on a string.  In
the next article, we'll show how to create a contract based on an interface.
</p>
        <p>
Code: <a href="http://www.davidgiard.com/content/binary/MEFDemo1.zip">MEFDemo1.zip
(563.48 KB)</a></p>
        <p>
          <font size="1">Note: The code in this article uses MEF CTP 5.</font>
        </p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb" />
      </body>
      <title>Simple Contracts in the Microsoft Managed Extensibility Framework</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb.aspx</guid>
      <link>http://www.davidgiard.com/2009/06/10/SimpleContractsInTheMicrosoftManagedExtensibilityFramework.aspx</link>
      <pubDate>Wed, 10 Jun 2009 10:43:53 GMT</pubDate>
      <description>&lt;p&gt;
Microsoft Managed Extensibility Framework (MEF) is a framework for building applications
composed of parts.&amp;nbsp; By constructing an application of parts, any part can be
replaced at runtime.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
In order to use this framework in your project, you will need to set reference to
System.ComponentModel.Composition.dll (which you can download from &lt;a href="http://codeplex.com/MEF"&gt;http://codeplex.com/MEF&lt;/a&gt;)
and add the following&amp;nbsp;statements to the top of any module with MEF code or attributes
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.ComponentModel.Composition;&lt;br&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;using&lt;/span&gt; System.ComponentModel.Composition.Hosting; &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The composition of MEF parts is very loosely coupled.&amp;nbsp; Coupling occurs using
contracts.&amp;nbsp; A contract consists of an Import and one or more Exports. 
&lt;/p&gt;
&lt;p&gt;
An Import is a place in your application that defines a variable but does not explicitly
state how that variable is implemented.&amp;nbsp; Instead, a declaration is decorated
with the [Import] attribute.&amp;nbsp; A parameter of the [Import] attribute describes
the implementation that the variable is seeking.&amp;nbsp; This parameter can be a string,
a type or an interface.&amp;nbsp; When MEF encounters an Import, it looks for an Export
that matches the Import's contract parameter.
&lt;/p&gt;
&lt;p&gt;
An Export is a class decorated with the [Export] attribute. This attribute tells MEF
that the class is available to satisfy any matching Import request.&amp;nbsp; Just as
with the [Import] attribute, the [Export] attribute accepts a parameter that is a
string, a type or an interface.
&lt;/p&gt;
&lt;p&gt;
For example, the following variable declaration
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Import(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MyMEFString"&lt;/span&gt;)] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; SomeString
{ get; set; } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;br&gt;
defines an import with a contract "MyMEFString". That contract is satisfied by the
following export
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; [Export(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"MyMEFString"&lt;/span&gt;)] &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; ThatExportedMefString
{ get { &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;return&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"This
string was provided by an MEF contract. It is from an external assembly."&lt;/span&gt;;
} } &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
Simply declaring this contract isn't enough.&amp;nbsp; We need to tell MEF to match up
the imports and exports.&amp;nbsp; The following steps are necessary for MEF to do its
thing&lt;br&gt;
1. Create a catalog.&amp;nbsp; A catalog tells MEF where to find the Imports and Exports.&lt;br&gt;
2. Create a container that uses the catalog.&lt;br&gt;
3. Create a batch and call the Compose method of that batch.&amp;nbsp; The Compose method
tells MEF to find the Imports and Exports that make up each contract and match them
up.
&lt;/p&gt;
&lt;p&gt;
If you want to compose parts that all exist in the currently executing assembly, this
is done with the following code
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; var
catalog &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; AssemblyCatalog(Assembly.GetExecutingAssembly());&lt;br&gt;
var container &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; CompositionContainer(catalog);&lt;br&gt;
var batch &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; CompositionBatch();&lt;br&gt;
batch.AddPart(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;this&lt;/span&gt;);&lt;br&gt;
container.Compose(batch); &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
The code above assumes that the contract's Exports and Imports are in the same project.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Notice the first line of code, in which we declare a variable named 'catalog'.&amp;nbsp;
This line instantiates a Catalog object.&amp;nbsp; A Catalog object defines where MEF
looks for parts.&amp;nbsp;&amp;nbsp;MEF supports the following types of Catalogs&amp;nbsp;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
An &lt;strong&gt;Assembly Catalog &lt;/strong&gt;retrieves MEF components compiled into a given
assembly. 
&lt;li&gt;
A &lt;strong&gt;Directory Catalog &lt;/strong&gt;retrieves all MEF components in all assemblies
in a given directory. 
&lt;li&gt;
An &lt;strong&gt;Aggregating Catalog&lt;/strong&gt; is used when you want to retrieve MEF components
from multiple places - for example, from a specific assembly and from a directory;
or from two different directories.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Of course it doesn't make much sense to go to the trouble of using a loosely-coupled
framework like MEF and getting your parts from the current assembly. In fact, it&amp;nbsp;often
doesn't make sense to get parts from an assembly that is known at design time.&amp;nbsp;
If we know the assembly name and location, we might as well set an explicit references
to it. 
&lt;/p&gt;
&lt;p&gt;
A more likely scenario is to import all MEF assemblies found in a specific folder.
To do this, we use a Directory Catalog.&amp;nbsp; We replace the declaration/initialization
of the catalog with the following line
&lt;/p&gt;
&lt;pre&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; folderToWatch &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;@"C:\Development\MEF\DGCode\MEFDemo1\MEFComponent1\bin\Debug"&lt;/span&gt;;&lt;br&gt;
var catalog &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; DirectoryCatalog(folderToWatch); &lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
By setting our catalog to a DirectoryCatalog, we tell MEF to search for imports in
all assemblies found in a well-known folder.&amp;nbsp; We can just drop DLLs into this
folder and MEF will find them and use them at runtime, even if our projects do not
set a reference to them.
&lt;/p&gt;
&lt;p&gt;
The &lt;em&gt;MEFDemo1 &lt;/em&gt;solution is a very simple sample that uses this code.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
In &lt;em&gt;MEFDemo1&lt;/em&gt;, a console application declares a string variable named "SomeString"
which is decorated with the Import attribute and defined by the contract "MyMEFString".&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
At runtime, MEF determines the The value of SomeString by searching for the Export
half of the contract.&amp;nbsp; It finds it in ThatExportedMefString variable, declared
in the &lt;em&gt;Class1 &lt;/em&gt;class of the &lt;em&gt;MEFComponent1 &lt;/em&gt;project.&amp;nbsp; MEF knows
to look here because we pointed a DirectoryCatalog at the folder where &lt;em&gt;MEFComponent1.dll &lt;/em&gt;is
compiled.&amp;nbsp; (If you copy this solution to a different directory, you will need
to change the path defined in &lt;em&gt;folderToWatch&lt;/em&gt; and recompile the &lt;em&gt;MEFComponent1 &lt;/em&gt;project.
In a real-world application, we would probably pull the folder name from a configuration
file or otherwise set it at runtime to make it even more flexible.)&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
The important point is that we don't need to set any references between these projects
in order for them to communicate.&amp;nbsp; The contract and MEF take care of this for
us.
&lt;/p&gt;
&lt;p&gt;
In this article, we showed a very simple MEF contract, based on a string.&amp;nbsp; In
the next article, we'll show how to create a contract based on an interface.
&lt;/p&gt;
&lt;p&gt;
Code: &lt;a href="http://www.davidgiard.com/content/binary/MEFDemo1.zip"&gt;MEFDemo1.zip
(563.48 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;Note: The code in this article uses MEF CTP 5.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,4aaafdbf-cb6b-4a59-b2b4-92e3bae8dcdb.aspx</comments>
      <category>MEF</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=79d8ce55-79fa-43d0-ad38-6631197c6160</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,79d8ce55-79fa-43d0-ad38-6631197c6160.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,79d8ce55-79fa-43d0-ad38-6631197c6160.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=79d8ce55-79fa-43d0-ad38-6631197c6160</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Microsoft Managed Extensibility Framework (MEF) is a framework for building extensible
applications. Using MEF, you can build extensible applications constructed of loosely-coupled
composable parts.  By constructing an application of parts, any part can be replaced
at runtime, without recompiling or redeploying the entire application.  
</p>
        <p>
One use would be to create an extensible application with a plug-in architecture,
allowing users to extend it or to replace parts of it, without recompiling. 
As such, you would not need to release the source code along with your application.  
</p>
        <p>
Microsoft already has several technologies to accomplish similar things.  Visual
Studio 2008 and Microsoft Office 2007 each has a plug-in framework that allows users
to extend the application.  MEF promises a single extensibility framework that
can be used across all Microsoft applications.  This frees developers from the
need to learn a different framework to extend each application.  In fact, the
editor in the upcoming Visual Studio 2010 (now in beta) is built on top of MEF, so
that developers can use MEF to add plug-ins to the IDE. 
</p>
        <p>
Of course, there are simpler technologies built into the .Net framework that allow
you to extend applications at runtime.  
</p>
        <p>
In the current version of .Net, we can code to interfaces, instead of concrete classes. 
Doing so gives us the ability to defer to runtime which class to instantiate. 
Our code is flexible enough to accept any class, as long as that class implements
the expected interface.  However, we must decide at compile time all possible
classes that might be instantiated at runtime.  This is because, in most cases,
we cannot instantiate a class without setting a reference to the assembly in which
that class resides.  And setting references is something done prior to compiling. 
Using MEF, we can instantiate classes even if there is no explicit reference set. 
MEF takes care of that for us.
</p>
        <p>
Managed Extensibility Framework promises to solve the problem of building loosely-coupled,
extensible applications without forcing developers to learn a new skill set for each
application.  It does so without the disadvantages of forcing a recompile and
loading classes into memory unnecessarily when an application is extended at runtime.
</p>
        <p>
          <font size="1">Note: As of this writing, MEF is in Community Technology 5 and is planned
to be released as part of .Net 4.0</font>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=79d8ce55-79fa-43d0-ad38-6631197c6160" />
      </body>
      <title>Why MEF?</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,79d8ce55-79fa-43d0-ad38-6631197c6160.aspx</guid>
      <link>http://www.davidgiard.com/2009/05/30/WhyMEF.aspx</link>
      <pubDate>Sat, 30 May 2009 17:35:37 GMT</pubDate>
      <description>&lt;p&gt;
Microsoft Managed Extensibility Framework (MEF) is a framework for building extensible
applications. Using MEF, you can build extensible applications constructed of loosely-coupled
composable parts.&amp;nbsp; By constructing an application of parts, any part can be replaced
at runtime, without recompiling or redeploying the entire application.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
One use would be to create an extensible application with a plug-in architecture,
allowing users to extend it or to replace parts of it, without recompiling.&amp;nbsp;
As such, you would not need to release the source code along with your application.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Microsoft already has several technologies to accomplish similar things.&amp;nbsp; Visual
Studio 2008 and Microsoft Office 2007 each has a plug-in framework that allows users
to extend the application.&amp;nbsp; MEF promises a single extensibility framework that
can be used across all Microsoft applications.&amp;nbsp; This frees developers from the
need to learn a different framework to extend each application.&amp;nbsp; In fact, the
editor in the upcoming Visual Studio 2010 (now in beta) is built on top of MEF, so
that developers can use MEF to add plug-ins to the IDE. 
&lt;/p&gt;
&lt;p&gt;
Of course, there are simpler technologies built into the .Net framework that allow
you to extend applications at runtime.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
In the current version of .Net, we can code to interfaces, instead of concrete classes.&amp;nbsp;
Doing so gives us the ability to defer to runtime which class to instantiate.&amp;nbsp;
Our code is flexible enough to accept any class, as long as that class implements
the expected interface.&amp;nbsp; However, we must decide at compile time all possible
classes that might be instantiated at runtime.&amp;nbsp; This is because, in most cases,
we cannot instantiate a class without setting a reference to the assembly in which
that class resides.&amp;nbsp; And setting references is something done prior to compiling.&amp;nbsp;
Using MEF, we can instantiate classes even if there is no explicit reference set.&amp;nbsp;
MEF takes care of that for us.
&lt;/p&gt;
&lt;p&gt;
Managed Extensibility Framework promises to solve the problem of building loosely-coupled,
extensible applications without forcing developers to learn a new skill set for each
application.&amp;nbsp; It does so without the disadvantages of forcing a recompile and
loading classes into memory unnecessarily when an application is extended at runtime.
&lt;/p&gt;
&lt;p&gt;
&lt;font size="1"&gt;Note: As of this writing, MEF is in Community Technology 5 and is planned
to be released as part of .Net 4.0&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=79d8ce55-79fa-43d0-ad38-6631197c6160" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,79d8ce55-79fa-43d0-ad38-6631197c6160.aspx</comments>
      <category>.Net</category>
      <category>MEF</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=dbed97a4-220a-4118-ad1d-ed79e635fad3</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,dbed97a4-220a-4118-ad1d-ed79e635fad3.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,dbed97a4-220a-4118-ad1d-ed79e635fad3.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=dbed97a4-220a-4118-ad1d-ed79e635fad3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <h4>
          <u>SPEAKING</u>
        </h4>
        <p>
I am scheduled to speak at the following upcoming events
</p>
        <p>
          <strong>CodeStock 2009</strong>
        </p>
        <p>
The CodeStock conference will be held in Knoxville, TN on June 27.  I will be
presentingon Microsoft Managed Extensibility Framework (MEF).  You can find information
on this event and register at <a href="http://codestock.org/" target="_blank">http://codestock.org/</a></p>
        <p>
          <strong>West Michigan .Net User Group</strong>
        </p>
        <p>
I will speak again on MEF at the July 14 meeting of the West Michigan .Net User Group
in Grand Rapids.  You can find more information at <a href="http://www.wmdotnet.org/" target="_blank">http://www.wmdotnet.org/</a></p>
        <h4>
          <u>LISTENING</u>
        </h4>
        <p>
I'll quietly spend all of Wednesday May 20 at the Microsoft office in Southfield so
that I can attend a series of events throughout the day.  The details are below:
</p>
        <p>
          <strong>ArcReady<br /></strong>Time: 9:00-11:45AM<br />
Topics: 
<br />
Trends and patterns on the client tier<br />
Applying Microsoft technology on the client tier<br />
Register: <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;EventID=1032408649" target="_blank">http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;EventID=1032408649</a><br />
 <br /><strong>MSDN Unleashed<br /></strong>Time: 1:00-3:00PM<br />
Topics:<br />
Internet Explorer 8 for Developers<br />
Developing on Microsoft Windows 7<br />
Register: <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;EventID=1032409548" target="_blank">http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;EventID=1032409548</a><br />
 <br /><strong>Technet Unleashed<br /></strong>Time: 3:10-5:00PM<br />
Topics:<br />
Windows Server 2008 R2 – Optimize Your Time<br />
Windows 7 – Maximize Your Potential<br />
Register: <a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;EventID=1032410548" target="_blank">http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;EventID=1032410548</a></p>
        <p>
          <strong>Southeast Michigan .Net User Group<br /></strong>Time: 3:10-5:00PM<br />
Topic: RIA<br />
More information:<br /><a href="http://migang.org/" target="_blank">http://migang.org/</a></p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=dbed97a4-220a-4118-ad1d-ed79e635fad3" />
      </body>
      <title>Upcoming speaking and listening schedule</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,dbed97a4-220a-4118-ad1d-ed79e635fad3.aspx</guid>
      <link>http://www.davidgiard.com/2009/05/19/UpcomingSpeakingAndListeningSchedule.aspx</link>
      <pubDate>Tue, 19 May 2009 17:13:25 GMT</pubDate>
      <description>&lt;h4&gt;&lt;u&gt;SPEAKING&lt;/u&gt;
&lt;/h4&gt;
&lt;p&gt;
I am scheduled to speak at the following upcoming events
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;CodeStock 2009&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The CodeStock conference will be held in Knoxville, TN on June 27.&amp;nbsp; I will be
presentingon Microsoft Managed Extensibility Framework (MEF).&amp;nbsp; You can find information
on this event and register at &lt;a href="http://codestock.org/" target=_blank&gt;http://codestock.org/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;West Michigan .Net User Group&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I will speak again on MEF at the July 14 meeting of the West Michigan .Net User Group
in Grand Rapids.&amp;nbsp; You can find more information at &lt;a href="http://www.wmdotnet.org/" target=_blank&gt;http://www.wmdotnet.org/&lt;/a&gt;
&lt;/p&gt;
&lt;h4&gt;&lt;u&gt;LISTENING&lt;/u&gt;
&lt;/h4&gt;
&lt;p&gt;
I'll quietly spend all of Wednesday May 20 at the Microsoft office in Southfield so
that I can attend a series of events throughout the day.&amp;nbsp; The details are below:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;ArcReady&lt;br&gt;
&lt;/strong&gt;Time: 9:00-11:45AM&lt;br&gt;
Topics: 
&lt;br&gt;
Trends and patterns on the client tier&lt;br&gt;
Applying Microsoft technology on the client tier&lt;br&gt;
Register: &lt;a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;amp;EventID=1032408649" target=_blank&gt;http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;amp;EventID=1032408649&lt;/a&gt; 
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;strong&gt;MSDN Unleashed&lt;br&gt;
&lt;/strong&gt;Time: 1:00-3:00PM&lt;br&gt;
Topics:&lt;br&gt;
Internet Explorer 8 for Developers&lt;br&gt;
Developing on Microsoft Windows 7&lt;br&gt;
Register: &lt;a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;amp;EventID=1032409548" target=_blank&gt;http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;amp;EventID=1032409548&lt;/a&gt; 
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;strong&gt;Technet Unleashed&lt;br&gt;
&lt;/strong&gt;Time: 3:10-5:00PM&lt;br&gt;
Topics:&lt;br&gt;
Windows Server 2008 R2 – Optimize Your Time&lt;br&gt;
Windows 7 – Maximize Your Potential&lt;br&gt;
Register: &lt;a href="http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;amp;EventID=1032410548" target=_blank&gt;http://msevents.microsoft.com/CUI/EventDetail.aspx?culture=en-US&amp;amp;EventID=1032410548&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Southeast Michigan .Net User Group&lt;br&gt;
&lt;/strong&gt;Time: 3:10-5:00PM&lt;br&gt;
Topic: RIA&lt;br&gt;
More information:&lt;br&gt;
&lt;a href="http://migang.org/" target=_blank&gt;http://migang.org/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=dbed97a4-220a-4118-ad1d-ed79e635fad3" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,dbed97a4-220a-4118-ad1d-ed79e635fad3.aspx</comments>
      <category>MEF</category>
      <category>Public Speaking</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=254d0d09-c570-4853-a84d-561e58d22c4b</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,254d0d09-c570-4853-a84d-561e58d22c4b.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,254d0d09-c570-4853-a84d-561e58d22c4b.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=254d0d09-c570-4853-a84d-561e58d22c4b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I gave a presentation (again) on the Microsoft Managed Extensibility framework. 
Below are the slides and demos used for this presentation.
</p>
        <p>
          <iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight="0" src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedgrid.aspx/Presentations/MEF/Managed%20Extensibility%20Framework.pptx" frameborder="0" marginwidth="0" scrolling="no">
          </iframe>
        </p>
        <p>
          <em>ProjetListDemo </em>A simple demo showing the syntax for MEF imports and exports 
</p>
        <p>
          <iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight="0" src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedgrid.aspx/Presentations/MEF/ProjectListDemo.zip" frameborder="0" marginwidth="0" scrolling="no">
          </iframe>
        </p>
        <p>
          <em>DemoAccounting </em>shows how to dynamically add modules to an application at
runtime, without recompiling.
</p>
        <p>
          <iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight="0" src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedgrid.aspx/Presentations/MEF/DemoAccounting.zip" frameborder="0" marginwidth="0" scrolling="no">
          </iframe>
        </p>
        <img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=254d0d09-c570-4853-a84d-561e58d22c4b" />
      </body>
      <title>MEF Presentation slides and demos</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,254d0d09-c570-4853-a84d-561e58d22c4b.aspx</guid>
      <link>http://www.davidgiard.com/2009/05/15/MEFPresentationSlidesAndDemos.aspx</link>
      <pubDate>Fri, 15 May 2009 02:26:06 GMT</pubDate>
      <description>&lt;p&gt;
Today&amp;nbsp;I gave a presentation (again) on the Microsoft Managed Extensibility framework.&amp;nbsp;
Below are the slides and demos used for this presentation.
&lt;/p&gt;
&lt;p&gt;
&lt;iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight=0 src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedgrid.aspx/Presentations/MEF/Managed%20Extensibility%20Framework.pptx" frameborder=0 marginwidth=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;ProjetListDemo &lt;/em&gt;A simple demo showing the syntax for MEF imports and exports&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight=0 src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedgrid.aspx/Presentations/MEF/ProjectListDemo.zip" frameborder=0 marginwidth=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;DemoAccounting &lt;/em&gt;shows how to dynamically add modules to an application at
runtime, without recompiling.
&lt;/p&gt;
&lt;p&gt;
&lt;iframe style="BORDER-BOTTOM: #dde5e9 1px solid; BORDER-LEFT: #dde5e9 1px solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: #ffffff; MARGIN: 3px; PADDING-LEFT: 0px; WIDTH: 94px; PADDING-RIGHT: 0px; HEIGHT: 94px; BORDER-TOP: #dde5e9 1px solid; BORDER-RIGHT: #dde5e9 1px solid; PADDING-TOP: 0px" marginheight=0 src="http://cid-7048ec40c0ac24c1.skydrive.live.com/embedgrid.aspx/Presentations/MEF/DemoAccounting.zip" frameborder=0 marginwidth=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=254d0d09-c570-4853-a84d-561e58d22c4b" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,254d0d09-c570-4853-a84d-561e58d22c4b.aspx</comments>
      <category>MEF</category>
      <category>Public Speaking</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=a7382437-9e6e-4adc-9ea8-d2e727bdbcd4</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,a7382437-9e6e-4adc-9ea8-d2e727bdbcd4.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,a7382437-9e6e-4adc-9ea8-d2e727bdbcd4.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a7382437-9e6e-4adc-9ea8-d2e727bdbcd4</wfw:commentRss>
      <slash:comments>10</slash:comments>
      <title>MEF slides</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,a7382437-9e6e-4adc-9ea8-d2e727bdbcd4.aspx</guid>
      <link>http://www.davidgiard.com/2008/11/10/MEFSlides.aspx</link>
      <pubDate>Mon, 10 Nov 2008 12:23:06 GMT</pubDate>
      <description>&lt;p&gt;
The slides for my MEF presentation are now available on Slideshare.&amp;nbsp; I have embedded
it below.
&lt;/p&gt;
&lt;p&gt;
I delivered this presentation at the &lt;a href="http://www.dayofdotnet.org/AnnArbor/Fall2008/" target=_blank&gt;ann
arbor Day of .Net in October&lt;/a&gt; and at a &lt;a href="http://www.us.sogeti.com/" target=_blank&gt;Sogeti&lt;/a&gt; grok
talk in November.
&lt;/p&gt;
&lt;p&gt;
I just signed up for Slideshare and I like the concept but it doesn't seem to support
any of the animations or transitions in my slides.&amp;nbsp; I may need to go to a video
sharing service for more dynamic slideshows.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div id=__ss_737730 style="WIDTH: 425px; TEXT-ALIGN: left"&gt;&lt;a title="Managed Extensibility Framework" style="DISPLAY: block; MARGIN: 12px 0px 3px; FONT: 14px Helvetica,Arial,Sans-serif; TEXT-DECORATION: underline" href="http://www.slideshare.net/dgiard/managed-extensibility-framework-presentation?type=powerpoint"&gt;Managed
Extensibility Framework&lt;/a&gt; 
&lt;object style="MARGIN: 0px" height=355 width=425&gt;
&lt;param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=microsoft-extensibility-framework-1226317900312598-9&amp;amp;stripped_title=managed-extensibility-framework-presentation"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=microsoft-extensibility-framework-1226317900312598-9&amp;stripped_title=managed-extensibility-framework-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;div style="FONT-SIZE: 11px; PADDING-TOP: 2px; FONT-FAMILY: tahoma,arial; HEIGHT: 26px"&gt;View
SlideShare &lt;a title="View Managed Extensibility Framework on SlideShare" style="TEXT-DECORATION: underline" href="http://www.slideshare.net/dgiard/managed-extensibility-framework-presentation?type=powerpoint"&gt;presentation&lt;/a&gt; or &lt;a style="TEXT-DECORATION: underline" href="http://www.slideshare.net/upload?type=powerpoint"&gt;Upload&lt;/a&gt; your
own. (tags: &lt;a style="TEXT-DECORATION: underline" href="http://slideshare.net/tag/mef"&gt;mef&lt;/a&gt; &lt;a style="TEXT-DECORATION: underline" href="http://slideshare.net/tag/net"&gt;.net&lt;/a&gt;)
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=a7382437-9e6e-4adc-9ea8-d2e727bdbcd4" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,a7382437-9e6e-4adc-9ea8-d2e727bdbcd4.aspx</comments>
      <category>MEF</category>
      <category>Public Speaking</category>
    </item>
    <item>
      <trackback:ping>http://www.davidgiard.com/Trackback.aspx?guid=f0339342-bc0f-4830-a58e-0044c8c0ef6e</trackback:ping>
      <pingback:server>http://www.davidgiard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.davidgiard.com/PermaLink,guid,f0339342-bc0f-4830-a58e-0044c8c0ef6e.aspx</pingback:target>
      <dc:creator>David Giard</dc:creator>
      <wfw:comment>http://www.davidgiard.com/CommentView,guid,f0339342-bc0f-4830-a58e-0044c8c0ef6e.aspx</wfw:comment>
      <wfw:commentRss>http://www.davidgiard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f0339342-bc0f-4830-a58e-0044c8c0ef6e</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Day of .Net recap</title>
      <guid isPermaLink="false">http://www.davidgiard.com/PermaLink,guid,f0339342-bc0f-4830-a58e-0044c8c0ef6e.aspx</guid>
      <link>http://www.davidgiard.com/2008/10/23/DayOfNetRecap.aspx</link>
      <pubDate>Thu, 23 Oct 2008 17:11:42 GMT</pubDate>
      <description>&lt;p&gt;
Saturday I had the pleasure of speaking at the &lt;a href="http://www.dayofdotnet.org/AnnArbor/Fall2008/" target=_blank&gt;ann
arbor Day of .Net&lt;/a&gt;.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
The event drew presenters and attendees from Michigan, Ohio and Indiana, demonstrating
what an impressive software development community we have here in the Midwest.
&lt;/p&gt;
&lt;p&gt;
My friend &lt;a href="http://nino.net" target=_blank&gt;Nino&lt;/a&gt; drove up Friday night to
stay at my place and we met other out-of-towners for dinner Friday night.
&lt;/p&gt;
&lt;p&gt;
I delivered a presentation on Microsoft's Managed Extensibility Framework ("MEF").&amp;nbsp;
The presentation was well-received.&amp;nbsp; The audience had many questions about the
technology afterwards and I noticed a few people from the audience posting on Twitter
about MEF in the days following the event.
&lt;/p&gt;
&lt;p&gt;
A new job and a tight project deadline kept me from working on my presentation until
a couple days prior to the event.&amp;nbsp; The good news is that I had presented on MEF
three times in the past.&amp;nbsp; The bad news was that the API had changed radically
since I developed my original presentation.&amp;nbsp; So I not only had to expand the
presentation to fit the time allotted, I had to completely rewrite my demo to match
the current API.&amp;nbsp; I was up most of Friday night and missed all the morning sessions
of the conference to finish on time for my 1PM presentation.&amp;nbsp;&amp;nbsp; Luckily I
finished successfully and the demos went off without a hitch.&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
I discovered a &lt;a href="http://blogs.msdn.com/brada/archive/2008/09/29/simple-introduction-to-composite-applications-with-the-managed-extensions-framework.aspx" target=_blank&gt;blog
entry&lt;/a&gt; by Brad Abrams that helped immensely.&amp;nbsp; Brad wrote a set of samples
using MEF that I loved for their simplicity.&amp;nbsp; Don't tell Brad, but I borrowed
liberally from his samples to populate one of my demos.
&lt;/p&gt;
&lt;p&gt;
After my presentation, I was able to settle in and enjoy the conference.&amp;nbsp; I attended
two sessions, both in the same room which suited my tired body.&amp;nbsp; &lt;a href="http://blogs.msdn.com/jennifer/" target=_blank&gt;Jennifer
Marsman&lt;/a&gt; showed a&amp;nbsp;bunch of new features in .Net 3.5.&amp;nbsp;&amp;nbsp;Next &lt;a href="http://www.brianhprince.com/" target=_blank&gt;Brian
Prince&lt;/a&gt; discussed the role of an architect on a project.&amp;nbsp; I've heard Jennifer
and Brian speak many times in the past, so I knew they would be good and I was not
disappointed.
&lt;/p&gt;
&lt;p&gt;
I did have time to poke my head into a few presentations long enough to snap a photo
or two.&amp;nbsp; If you heard a clicking coming from the doorway, that was me.
&lt;/p&gt;
&lt;p&gt;
After the event, many of us met at a local watering hole for some food, drink and
fellowship.&amp;nbsp; My new employer &lt;a href="http://us.sogeti.com/" target=_blank&gt;Sogeti&lt;/a&gt; was
kind enough to spring for the food and drinks.&amp;nbsp; I was well worn down but it was
great to reconnect with people who share many of my passions.
&lt;/p&gt;
&lt;p&gt;
I actually volunteered to be something called a "Venue Coordinator" for this event.&amp;nbsp;
But, as this was the fourth time the event was held, the folks at Washtenaw Community
College knew everything that needed to be done and delivered to perfection.&amp;nbsp;
I ended up doing no work for this role, so I may volunteer as venue coordinator next
year as well.
&lt;/p&gt;
&lt;p&gt;
I took some photos at the event, which you can see &lt;a href="http://www.flickr.com/photos/29942169@N08/sets/72157608242633229/" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I also put together a slideshow with a Warren Zevon soundtrack that you can see and
hear below:&amp;nbsp;
&lt;/p&gt;
&lt;object height=344 width=425&gt;
&lt;param name="movie" value="http://www.youtube.com/v/x8yDS4AVoX8&amp;amp;hl=en&amp;amp;fs=1"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;embed src="http://www.youtube.com/v/x8yDS4AVoX8&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"&gt;&lt;/embed&gt;
&lt;/object&gt;&lt;img width="0" height="0" src="http://www.davidgiard.com/aggbug.ashx?id=f0339342-bc0f-4830-a58e-0044c8c0ef6e" /&gt;</description>
      <comments>http://www.davidgiard.com/CommentView,guid,f0339342-bc0f-4830-a58e-0044c8c0ef6e.aspx</comments>
      <category>Community</category>
      <category>Public Speaking</category>
      <category>MEF</category>
    </item>
  </channel>
</rss>