<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>My Technobabble</title><link>http://blogs.msdn.com/gblock/default.aspx</link><description>Glenn Block - .NETFX&lt;BR&gt;
&lt;script type="text/javascript" src="http://settings.messenger.live.com/controls/1.0/PresenceButton.js"&gt;&lt;/script&gt;
&lt;div
  id="Microsoft_Live_Messenger_PresenceButton_f8b2fd72406fb218"
  msgr:width="100"
  msgr:backColor="#D7E8EC"
  msgr:altBackColor="#FFFFFF"
  msgr:foreColor="#424542"
  msgr:conversationUrl="http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=f8b2fd72406fb218@apps.messenger.live.com&amp;mkt=en-US"&gt;&lt;/div&gt;
&lt;script type="text/javascript" src="http://messenger.services.live.com/users/f8b2fd72406fb218@apps.messenger.live.com/presence?dt=&amp;mkt=en-US&amp;cb=Microsoft_Live_Messenger_PresenceButton_onPresence"&gt;&lt;/script&gt;
&lt;br&gt;
Another ALT.NET guy at Microsoft</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/MyTechnobabble" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item><title>Building extensible RIAs at PDC</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/oLK0JTydxw4/building-extensible-rias-at-pdc.aspx</link><pubDate>Mon, 16 Nov 2009 18:14:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9923065</guid><dc:creator>Glenn Block</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9923065.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9923065</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9923065</wfw:comment><description>&lt;p&gt;&lt;a href="http://microsoftpdc.com/"&gt;&lt;img title="image" border="0" alt="image" align="left" src="http://blogs.msdn.com/blogfiles/brada/WindowsLiveWriter/PDC2009Icantwait_88A8/image_3.png" width="325" height="88" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This week I’ll be attending PDC in Los Angeles speaking about using MEF in Silverlight.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://microsoftpdc.com/Sessions/FT24"&gt;Building Extensible Rich Internet Applications with the Managed Extensibility Framework&lt;/a&gt;&amp;#160;&lt;/p&gt;    &lt;p&gt;In Hall F on Thursday at 11:30 AM&lt;/p&gt;    &lt;p&gt;Learn how the Microsoft .NET Framework 4 introduces the Managed Extensibility Framework (MEF) for building customizable applications that can easily be extended by third parties. Whether you are building an extensible data grid, a custom rules engine, a pluggable editor, or a composite application such as a pluggable CRM system, you want to learn about MEF. Hear how to use MEF to decouple your applications into more maintainable and testable pieces, and partition your application into dynamically deployable chunks that download on-demand.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;If you haven’t heard, &lt;a href="http://mef.codeplex.com"&gt;MEF&lt;/a&gt; is available in Silverlight similar to it’s availability on the desktop.&amp;#160; But what does it mean to build an extensible app in Silverlight? Yes it’s technically possible, but why should you care? In this talk we’ll explore different application scenarios for when MEF is a good fit. We’ll also explore some of the SL specific features we’ve introduced in order to enrich the MEF experience.&lt;/p&gt;  &lt;p&gt;Hope to see you there!&lt;/p&gt;  &lt;p&gt;Glenn &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9923065" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=oLK0JTydxw4:-vxZtV74Fio:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=oLK0JTydxw4:-vxZtV74Fio:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=oLK0JTydxw4:-vxZtV74Fio:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=oLK0JTydxw4:-vxZtV74Fio:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=oLK0JTydxw4:-vxZtV74Fio:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=oLK0JTydxw4:-vxZtV74Fio:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=oLK0JTydxw4:-vxZtV74Fio:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/silverlight/default.aspx">silverlight</category><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/RIA/default.aspx">RIA</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/11/16/building-extensible-rias-at-pdc.aspx</feedburner:origLink></item><item><title>Should I use MEF with an IoC container? - Part 1</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/KTBaGEf6exI/should-i-use-mef-with-an-ioc-container-part-1.aspx</link><pubDate>Sun, 01 Nov 2009 10:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9915829</guid><dc:creator>Glenn Block</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9915829.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9915829</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9915829</wfw:comment><description>&lt;P&gt;In my post &lt;A href="http://codebetter.com/blogs/glenn.block/archive/2009/08/16/should-i-use-mef-for-my-general-ioc-needs.aspx" mce_href="http://blogs.msdn.com/blogs/glenn.block/archive/2009/08/16/should-i-use-mef-for-my-general-ioc-needs.aspx"&gt;"Should I use MEF for my IoC needs"&lt;/A&gt;&amp;nbsp;we took a look at the question of whether or not it is appropriate to use MEF instead of a traditional&amp;nbsp;IoC container. In this post we'll discuss the question of whether or not you should use both an IoC container and MEF in the same application. &lt;/P&gt;
&lt;H2&gt;MEF and IoC container concerns&lt;/H2&gt;
&lt;P&gt;As we've mentioned in the past, MEF's primary design in V1&amp;nbsp;is&amp;nbsp;around open-systems whose components (parts) are dynamically discovered at runtime. IoC containers on the other hand are primarily&amp;nbsp;designed for&amp;nbsp;decoupling&amp;nbsp;a closed&amp;nbsp;(fixed) set of application components in order to&amp;nbsp;improve the maintainability of the system by the engineering team. In other words each is addressing a specific set of concerns. So if that is the case then is it plausable to use both in an application? The answer is &lt;STRONG&gt;Yes&lt;/STRONG&gt;. Not only that, but we specifically designed MEF with the idea of integration with other containers in mind. Below will explore one of the key-scenarios for doing this.&lt;/P&gt;
&lt;H2&gt;Enabling third-party extensibility in an IoC container-dependent application.&amp;nbsp;&lt;/H2&gt;
&lt;P&gt;You have an existing customer management system that uses an IoC container such as Castle Windsor which you use in order to promote separation-of-concens and testability. The application leverages advanced Windsor facilities for integrating with NHibernate and for applying cross-cutting-concerns (AOP) such as logging, etc. The loosely coupled design of the system has proven to be greatly beneficial and has minimized the friction for developing and deploying the system through several releases. &lt;/P&gt;
&lt;P&gt;At some point requests start pouring in&amp;nbsp;from customers want to create their own extensions in order to customize the application in their specific environments. Additionally several ISVs express interest in providing third-party&amp;nbsp;value-adds such as telephony integration, and scheduling.&amp;nbsp;&amp;nbsp;You determine that adding a third-party&amp;nbsp;extensibility model to the application makes sense in order to address this opportunity. Through your&amp;nbsp;research you come across MEF and realize that it provides the infrastructure you need for extensibility.&amp;nbsp; However&amp;nbsp;it does so&amp;nbsp;in a manner that&amp;nbsp;overlaps with&amp;nbsp;many of the&amp;nbsp;functions that Windsor is providing.&amp;nbsp;What to do? Let's explore various options.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;a. Migrate the existing code to use MEF and remove&amp;nbsp;the IoC container&amp;nbsp;completely.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;One option is to consider ripping out Castle and just using MEF. Technically this&amp;nbsp;sounds reasonable, however after investigation&amp;nbsp;it is not feasible. There are literally thousands&amp;nbsp;of components that are currently registered in the Windsor container.&amp;nbsp;Moving these to MEF&amp;nbsp;involves modfying all of these existing classes&amp;nbsp;in order to make them discoverable by MEF, not to mention refactoring all the places in the application where the container is accessed.&amp;nbsp; Because the changes are so widespread, the likelihood of introducing&amp;nbsp; breakages / bugs in the system is very high. Additionally there are the various Castle facilities such as Dynamic Proxy, and NHibernate integration&amp;nbsp;which MEF does not yet support, which will have to authored by the team. The cost / risk of such changes is too prohibitive, not to mention that it seems&amp;nbsp;like it should be unnecessary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;b. Implement a custom&amp;nbsp;extensibility mechanism&amp;nbsp;built on top of the&amp;nbsp;IoC container?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Another option is to author a home-grown solution. This can be a viable option depending on the needs, and the willingness to author your own solution. For simple cases you can easily facade an extensibility mechanism on top of an IoC. Once you start getting into more advanced features like lazy instantiation, metadata, recomposition and stable composition, you are in for quite a bit of work. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;c. Have&amp;nbsp;both&amp;nbsp;the IoC&amp;nbsp;and MEF both present in the same application?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The final option I want to discuss (and the one I recommend for these situations) is to use both. Use the IoC container for addressing internal application decoupling needs, and use MEF for third-party extensibiltiy needs, that is the IoC container for IoCish things and the MEF container for MEFfish things :-)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This path is appealing for several reasons. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;It works with existing codebases whether they be applications or frameworks. it does not require any significant rewrite.&lt;/LI&gt;
&lt;LI&gt;It allows leveraging the strengths of each container for the things it does best. For example leveraging MEF's metadata model for discriminating between different extensions vs the dynamic proxy support in Castle. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;However, there are several caveats of this approach.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;It&amp;nbsp;raises questions such as: 
&lt;UL&gt;
&lt;LI&gt;Which component (part) should live in which container? &lt;/LI&gt;
&lt;LI&gt;Who owns the lifetime?&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Can a MEF part access services coming from the IoC?&amp;nbsp; How?&lt;/LI&gt;
&lt;LI&gt;Can the IoC access exports coming from MEF?&amp;nbsp;&amp;nbsp;How?&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;It increases complexity in that now there are components living in mulitple places. &lt;/LI&gt;
&lt;LI&gt;It increases the potential points of failuire within the application. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;All of these issues are managable. In my next post we'll see how.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915829" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=KTBaGEf6exI:bNA6w9VNPmM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=KTBaGEf6exI:bNA6w9VNPmM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=KTBaGEf6exI:bNA6w9VNPmM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=KTBaGEf6exI:bNA6w9VNPmM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=KTBaGEf6exI:bNA6w9VNPmM:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=KTBaGEf6exI:bNA6w9VNPmM:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=KTBaGEf6exI:bNA6w9VNPmM:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/ioc/default.aspx">ioc</category><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/11/01/should-i-use-mef-with-an-ioc-container-part-1.aspx</feedburner:origLink></item><item><title>Open-generic support in MEF Contrib</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/RR7aBw2IkB0/open-generic-support-in-mef-contrib.aspx</link><pubDate>Thu, 20 Aug 2009 11:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9876634</guid><dc:creator>Glenn Block</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9876634.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9876634</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9876634</wfw:comment><description>&lt;p&gt;A while ago I &lt;a href="http://blogs.msdn.com/blogs/glenn.block/archive/2009/03/21/why-doesn-t-mef-support-open-generics-for-exports-because-mef-is-not-type-based.aspx"&gt;said&lt;/a&gt; it couldn’t be done, at least without hacky string parsing. Folks weren’t happy and they let us know it including &lt;a href="http://ayende.com/Blog/archive/2009/03/22/mef-open-generic-types.aspx"&gt;Oren&lt;/a&gt;. Our team know the power that open-generic support brings to systems, but at the time there was no clean way to implement it in MEF.&amp;#160; Then a bunch of time passed, and we actually added some APIs to MEF&amp;#160; which suddenly made achieving support a reality (thanks to &lt;a href="http://weblogs.asp.net/whaggard/"&gt;Wes&lt;/a&gt; for pointing the path), and not in the hacky string-parsing way I had described. &lt;/p&gt;  &lt;p&gt;It all came together a few weeks ago after I was pairing with my friend Karl Shifflett on the Cider team. We ran into an issue around usage of MEF which really needed open-generics, and without it made me question the usage of MEF for that scenario.&amp;#160; As I have a &lt;a href="http://blogs.msdn.com/blogs/glenn.block/archive/2009/04/27/poco-mef-and-custom-type-systems-are-you-ready-to-take-the-red-pill.aspx"&gt;tendency&lt;/a&gt; to do, I then set off on a personal &lt;a href="http://twitter.com/gblock/status/3135292859"&gt;mission&lt;/a&gt; to find a solution. And now several weeks and light nights later, and after quite a bit of help from many of my teammates I am happy to say there is one! I am a tech geek so I usually now take the opportunity to dive into all the nitty gritty of what what the implementation is. This time however, I am going to change that tune and only focus on what it is, how you use it and how you can get it (now).&lt;/p&gt;  &lt;h2&gt;How can I get it?&lt;/h2&gt;  &lt;p align="left"&gt;If you want to get right to the code, then GenericCatalog ships as part of &lt;a href="http://mefcontrib.codeplex.com/"&gt;MEF Contrib&lt;/a&gt;. I’ve uploaded two projects MefContrib.Extenions.Generics and MefContrib.Extensions.Generics.Tests. You can go grab the source on contrib&amp;#160; &lt;a href="http://mefcontrib.codeplex.com/SourceControl/changeset/view/27092"&gt;here&lt;/a&gt;. Andreas is shortly releasing an official release of MEF Contrib, which will contain this in binary form. If you want the binary, tweet &lt;a href="http://twitter.com/thecodejunkie"&gt;Andreas&lt;/a&gt; and say I want MEF Contrib!&lt;/p&gt;  &lt;h2&gt;What is it?&lt;/h2&gt;  &lt;p&gt;Open-generic support is very simple. It means that you can provide a part with a generic contract, that can be used to satisfy all imports of a closed form of that contract. The canonical example folks use is Repository&amp;lt;T&amp;gt; and IRepository&amp;lt;T&amp;gt;. What I want to be able to do is register a generic Repository such that any imports of IRepository&amp;lt;T&amp;gt; can be satisfied, this IRepository&amp;lt;Customer&amp;gt;, IRepository&amp;lt;Order&amp;gt;, etc can all be handled by a single Repository&amp;lt;T&amp;gt; that is registered in the catalog. &lt;/p&gt;  &lt;p&gt;MEF’s attributed model however does not support this, we don’t allow even exporting open-generic types. If you put an export attribute on say Repository&amp;lt;T&amp;gt;, we ignore it. MEF does support closed generic types. For example I can have an importer of IRepository&amp;lt;Customer&amp;gt;, and i can register Repository&amp;lt;Customer&amp;gt; which exports IRepository&amp;lt;Customer&amp;gt;. However, that means that I have to add a specific implementation of IRepository&amp;lt;T&amp;gt; for every repository in existence. This is problematic because the importer doesn’t want to be burdened with having to add these specific implementations, or to know whether or not it even exists.&lt;/p&gt;  &lt;h2&gt;Enter GenericCatalog&lt;/h2&gt;  &lt;p&gt;The new GenericCatalog changes that. Generic Catalog is a custom catalog that can both discover open-generic implementations, and create closed implementations on demand. It also supports generic specialization, that is it allows you to register specific implementations of a generic contract, which override the default that will be created by the open-generic. Finally it supports one other requested feature, that is it can create concrete instances that are imported, even if they were not added to any catalog. &lt;/p&gt;  &lt;p&gt;GenericCatalog is a decorator. You pass it in it’s constructor all your catalogs, and it sits on top, delegates to the inner catalogs, and intercepts requests for generic types that were not found in the catalog.&lt;/p&gt;  &lt;h2&gt;How you use it&lt;/h2&gt;  &lt;p&gt;To see how it works, check out the specification / context below (otherwise known as a unit test)&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;   &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;     &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;[TestFixture]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; When_querying_catalog_for_an_order_repository_and_no_closed_repository_is_present : GenericCatalogContext&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    [Test]                    &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; order_repository_part_definition_is_created()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        Assert.IsNotNull(_result.Item1);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    [Test]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; order_repository_export_is_created()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        Assert.IsNotNull(_result.Item2);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Context()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _result = _genericCatalog.GetExports(_repositoryImportDefinition).Single();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; Tuple&amp;lt;ComposablePartDefinition, ExportDefinition&amp;gt; _result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Looking at the spec we can see that we are creating the container passing in a generic catalog. We are then asking the container for an IRepository&amp;lt;Order&amp;gt; and we are verifying that we got one. &lt;/p&gt;

&lt;p&gt;Notice in the test that we are calling the overload that accepts an ImportDefinition rather than just calling container.GetExportedValue&amp;lt;IRepository&amp;lt;Order&amp;gt;&amp;gt;. MEF creates special kinds of ImportDefinitions when you add an Import to a part. These definitions carry additional information that the generics implementation relies on. When you call GetExport directly on the container however, the definition that is created is a different definition which doe snot carry this information. As such, in order to take advantage of the new functionality, you import the generic type in a part. For example, the IRepository&amp;lt;Order&amp;gt; definition came from this import below.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;[Export]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; OrderProcessor&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    [Import]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; IRepository&amp;lt;Order&amp;gt; OrderRepository { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;OrderProcessor is importing IRepository&amp;lt;Order&amp;gt;&lt;/p&gt;

&lt;h2&gt;How do you setup the container?&lt;/h2&gt;

&lt;p&gt;In order to setup the container to support open-generics, you create the GenericCatalog passing in all your other catalogs, usually this will be your conventional AggregateCatalog that contains all your catalogs today. For example below in the base context class you can see how we setup the catalog for this test.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; GenericCatalogContext&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; AggregateCatalog _aggegateCatalog;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; GenericCatalog _genericCatalog;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; ImportDefinition _repositoryImportDefinition;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; GenericCatalogContext()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        var typeCatalog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TypeCatalog(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(OrderProcessor), &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(RepositoryTypeLocator));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _aggegateCatalog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; AggregateCatalog();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _aggegateCatalog.Catalogs.Add(typeCatalog);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _genericCatalog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; GenericCatalog(_aggegateCatalog);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; orderProcessorContract = AttributedModelServices.GetContractName(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(OrderProcessor));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        var orderProcessPartDefinition = typeCatalog.Parts.Single(p =&amp;gt; p.ExportDefinitions.Any(d =&amp;gt; d.ContractName == orderProcessorContract));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        _repositoryImportDefinition = orderProcessPartDefinition.ImportDefinitions.First();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        Context();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Context()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In this case we are creating a type catalog that we are adding our types for our test, an OrderProcessor and a RepositoryTypeLocator (more about that in the next section). Next we are creating an AggregateCatalog, and adding the type catalog to it. Finally we are creating a GenericCatalog and passing it the Aggregate which contains everything else. Next I do a bit of hackery to get the ImportDefinition off of the OrderProcessor in order to do the query in the test. As i mentioned you shouldn’t have to do this, as you’ll be grabbing something from the container that likely depends on the generic import rather than needed it directly.&lt;/p&gt;

&lt;h2&gt;Type Mapping&lt;/h2&gt;

&lt;p&gt;If you are following along, you might be asking yourself where are the open-generic types? And that is where GenericTypeMapping comes in. As I mentioned earlier, MEF does not allow exporting / importing&amp;#160; open-generics. To work around that, I’ve introduced a non-generic contract that carries generic type information :-) Not only that, but the implementation types passed in actually are open-generic parts!&lt;/p&gt;

&lt;p&gt;GenericTypeMapping accepts two parameters in it’s constructor, one is an open-generic contract type, and the other is an open-generic implementation type. This type also is an inherited export, taking advantage of our new Preview 6 feature which thus removes the need for the attribute on derivers.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;[InheritedExport]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;abstract&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; GenericContractTypeMapping&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; GenericContractTypeMapping(Type genericContractTypeDefinition, Type genericImplementationTypeDefinition)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Type GenericContractTypeDefinition { get; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; Type GenericImplementationTypeDefinition { get; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;To use it, you derive from GenericContractTypeMapping for each open-generic type you want to export. You then make sure that it is in one of the catalogs that is passed in to the GenericCatalog. In our example we have a RepositoryTypeLocator which has a contract of IRepository&amp;lt;&amp;gt; and an implementation of Repository&amp;lt;&amp;gt;.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; RepositoryTypeLocator : GenericContractTypeMapping&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; RepositoryTypeLocator()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        :&lt;span style="color: #0000ff"&gt;base&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(IRepository&amp;lt;&amp;gt;), &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Repository&amp;lt;&amp;gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Repository&amp;lt;&amp;gt; is a generic part. It supports constructor injection, can have imports / exports just like any other part. &lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Repository&amp;lt;T&amp;gt; : IRepository&amp;lt;T&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So all you have to do is create generic parts, and corresponding type mappings, put them in the catalog, and as Karl Shifflett says, “DONE!”&lt;/p&gt;

&lt;h2&gt;How it works (You don’t have to read this)&lt;/h2&gt;

&lt;p&gt;GenericCatalog is what is doing all the magic here. This guy automatically queries&amp;#160; his inner catalog for all GenericTypeMapping contacts. Once he has them, he takes the types within and adds them to a mapping table from generic contract to generic implementation. Whenever the catalog is queried, it will see if any exports were returned, if not and the importing type is generic, it will grab the generic type definition, and lookup in that table built earlier. If it finds that it can match against that definition, it will grab the implementation and create a closed generic type. It will then add the new type to a TypeCatalog, which it will add to it’s inner catalog.&amp;#160; Once it does this, it then queries the catalog to grab the new export, returns it, and Voila.&lt;/p&gt;

&lt;p&gt;You can dig into the source if you want to know more of the nitty gritty.&lt;/p&gt;

&lt;h1&gt;&lt;/h1&gt;

&lt;h2&gt;Will this ship as part of MEF V1?&lt;/h2&gt;

&lt;p&gt;No. Actually being brutally honest, the implementation here would probably never ship as part of the framework. This is an additive approach to solving the problem of open-generics, but it is not the approach we would choose to ship in the framework. We are looking seriously into baking such support into MEF in the future, but it will not be in V1. If and when we do, I guarantee it will be a much cleaner and deeply integrated part of MEF as opposed to what I am giving you. However, I believe as do others on my team that in the meanwhile, this approach is reasonable. We’ve put this in MEF contrib to ensure that the community can take it forward from here.&lt;/p&gt;

&lt;p&gt;We appreciate any feedback. I take full responsibility for any hackiness you find within. :p&lt;/p&gt;

&lt;p&gt;Special thanks to all my awesome teammates and to &lt;a href="http://www.thecodejunkie.com/"&gt;Andreas&lt;/a&gt; for help in getting this out the door.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9876634" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=RR7aBw2IkB0:9neK_W7Mjwg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=RR7aBw2IkB0:9neK_W7Mjwg:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=RR7aBw2IkB0:9neK_W7Mjwg:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=RR7aBw2IkB0:9neK_W7Mjwg:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=RR7aBw2IkB0:9neK_W7Mjwg:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=RR7aBw2IkB0:9neK_W7Mjwg:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=RR7aBw2IkB0:9neK_W7Mjwg:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/generics/default.aspx">generics</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/08/20/open-generic-support-in-mef-contrib.aspx</feedburner:origLink></item><item><title>Herding code on MVVM and other presentation patterns in WPF and Silverlight</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/aJ4OjIZqZ5I/herding-code-on-mvvm-and-other-presentation-patterns-in-wpf-and-silverlight.aspx</link><pubDate>Thu, 20 Aug 2009 09:17:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9876445</guid><dc:creator>Glenn Block</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9876445.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9876445</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9876445</wfw:comment><description>&lt;p&gt;Recently I had the pleasure of having a nice lively discussion on &lt;a href="http://herdingcode.com/?p=208"&gt;Herding Code&lt;/a&gt; with my cohorts &lt;a href="http://neverindoubtnet.blogspot.com/"&gt;Ward Bell&lt;/a&gt;,&amp;#160; &lt;a href="http://devlicio.us/blogs/rob_eisenberg/archive/2009/08/19/herding-code-57-presentation-pattern-goodness.aspx"&gt;Rob Eisenberg&lt;/a&gt; and &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2009/08/19/presentation-patterns-on-herding-code.aspx"&gt;Jeremy Miller&lt;/a&gt; around one of our favorite topics, Presentation Patterns. We let the gloves come off and went at it for about 2 hours. The conversation ranged from topics including View First vs VM First, Screen activation, commanding, and databinding. The podcast was a blast.&amp;#160; Special thanks to the Herding Code team for their being great hosts, and for their awesome queuing system. Even I let others speak :-) &lt;/p&gt;  &lt;p&gt;Get part I here: &lt;a href="http://herdingcode.com/?p=208"&gt;Herding Code 57: Presentation Patterns with Jeremy Miller, Ward Bell, Rob Eisenberg and Glenn Block (Part 1)&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9876445" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=aJ4OjIZqZ5I:dWO31Hr534c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=aJ4OjIZqZ5I:dWO31Hr534c:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=aJ4OjIZqZ5I:dWO31Hr534c:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=aJ4OjIZqZ5I:dWO31Hr534c:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=aJ4OjIZqZ5I:dWO31Hr534c:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=aJ4OjIZqZ5I:dWO31Hr534c:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=aJ4OjIZqZ5I:dWO31Hr534c:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/silverlight/default.aspx">silverlight</category><category domain="http://blogs.msdn.com/gblock/archive/tags/MVVM/default.aspx">MVVM</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/08/20/herding-code-on-mvvm-and-other-presentation-patterns-in-wpf-and-silverlight.aspx</feedburner:origLink></item><item><title>Should I use MEF for my general IoC needs?</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/tiD7GvAWkH4/should-i-use-mef-for-my-general-ioc-needs.aspx</link><pubDate>Sun, 16 Aug 2009 22:37:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9871777</guid><dc:creator>Glenn Block</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9871777.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9871777</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9871777</wfw:comment><description>&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Disclaimer: This is not an encouragement to use MEF&amp;nbsp;to replace your IoC container, these are guidelines&amp;nbsp;to help those who are considering it's use.&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This has been a question we hear again and again both internally and externally.&amp;nbsp; MEF in V1 is targetting third-party extensibility scenarios, or open-systems which discover their components rather than having them explicitly configured. This is why our attributed model was crafted in the fashion that it was.&amp;nbsp; Now that doesn’t answer the question, “Can I use MEF today for my general IoC needs?”. Like all things in software, it depends ;-), in this case on what your IoC needs are. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Update: The list has been updated based on feedback from my team.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;On first glance, MEF may seem to be very similar to your favorite IoC container. However as they say, the devil is in the details. Here are a few details to consider which should help you in your decision and set proper expectations about using MEF:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If you&amp;nbsp; need/want centralized configuration of plain old CLR objects (POCOs) then MEF is not the right choice. 
&lt;UL&gt;
&lt;LI&gt;We do have TypeCatalogs which allow you pick and choose which Types you have in the container, but those types &lt;U&gt;still have to attributed&lt;/U&gt;, thus the configuration mechanism is configuring which attributed MEF parts show up. This is because our attributed model is really optimized around discovery of a set of unknown components vs configuring a pre-defined set. &lt;/LI&gt;
&lt;LI&gt;As we don't have a central configuration mechanism, we also have no explict way to pipe configuration settings like "Port" or "Uri" into a specific part.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;If you need AOP/Interception like injecting logging, or automatic transcation management then MEF doesn’t include any native support for this. &lt;/LI&gt;
&lt;LI&gt;Open generics support (register IRepository&amp;lt;&amp;gt; which can handle all IRepository&amp;lt;T&amp;gt; dependencies) is not baked in. &lt;/LI&gt;
&lt;LI&gt;If you need custom lifetime support such as per-thread, per-session MEF includes only two lifetime models, shared and non-shared. To get more complex lifetimes requires manually setting up container hierarchies. It is doable, but requires work. &lt;/LI&gt;
&lt;LI&gt;If you need paramterized construction, that is creating a part where specific imports are passed in at the time of construction, then this is also not supported.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In enterprise applications with a large number of different types of components, the above list will probably be more significant. However, if none of the above are core concerns then MEF might be fine for your needs.&amp;nbsp;&amp;nbsp;&amp;nbsp; MEF does an excellent job of decoupling implementations and assembling component hierarchies, but it is tailored today for implicit composition and discovery.&lt;/P&gt;
&lt;P&gt;In the next version of MEF that will ship post .NET 4.0,&amp;nbsp; we are planning to focus more on explicit composition, and will be addressing many of the items on the above list. Until then, it is likely that there will be some great community implementations such as &lt;A href="http://mefcontrib.codeplex.com/" mce_href="http://mefcontrib.codeplex.com"&gt;MEF Contrib&lt;/A&gt; which will address many of these concerns, but these are not part of MEF itself.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9871777" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=tiD7GvAWkH4:viiMSOZ4b8s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=tiD7GvAWkH4:viiMSOZ4b8s:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=tiD7GvAWkH4:viiMSOZ4b8s:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=tiD7GvAWkH4:viiMSOZ4b8s:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=tiD7GvAWkH4:viiMSOZ4b8s:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=tiD7GvAWkH4:viiMSOZ4b8s:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=tiD7GvAWkH4:viiMSOZ4b8s:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/08/16/should-i-use-mef-for-my-general-ioc-needs.aspx</feedburner:origLink></item><item><title>The spirit of MVVM (ViewModel), it’s not a code counting exercise.</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/zMy8tgdMTtU/the-spirit-of-mvvm-viewmodel-it-s-not-a-code-counting-exercise.aspx</link><pubDate>Mon, 03 Aug 2009 08:13:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9855916</guid><dc:creator>Glenn Block</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9855916.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9855916</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9855916</wfw:comment><description>&lt;p&gt;&amp;lt;Warning&amp;gt;Long post follows&amp;lt;/Warning&amp;gt;&lt;/p&gt;  &lt;p&gt;Lately there is a lot of momentum and interesting &lt;a href="http://search.twitter.com/search?q=&amp;amp;ands=&amp;amp;phrase=&amp;amp;ors=MVVM+ViewModel&amp;amp;nots=&amp;amp;tag=&amp;amp;lang=en&amp;amp;from=&amp;amp;to=&amp;amp;ref=&amp;amp;near=&amp;amp;within=15&amp;amp;units=mi&amp;amp;since=&amp;amp;until=&amp;amp;rpp=50"&gt;conversation&lt;/a&gt; around Model-View-View-Model. There’s several good resources out there that discuss the basics of the pattern, who the actors are that are involved and what role the play. I’ll let those speak for themselves, including &lt;a href="http://blogs.msdn.com/johngossman"&gt;John Gossman’s&lt;/a&gt; great &lt;a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx"&gt;post&lt;/a&gt; here, Martin Fowler’s post on the more general &lt;a href="http://martinfowler.com/eaaDev/PresentationModel.html"&gt;PresentationModel&lt;/a&gt; pattern and more recently &lt;a href="http://joshsmithonwpf.wordpress.com/"&gt;Josh Smith’s&lt;/a&gt; MSDN &lt;a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx"&gt;article&lt;/a&gt;, Rob Eisenberg’s new &lt;a href="http://devlicio.us/blogs/rob_eisenberg/archive/2009/07/07/mvvm-philosophy-and-case-studies-introduction.aspx"&gt;series&lt;/a&gt;, and Ward Bell’s &lt;a href="http://neverindoubtnet.blogspot.com/2009/05/birth-and-death-of-m-v-vm-triads.html"&gt;posts&lt;/a&gt; which touch on some of the deeper complexities involved.&lt;/p&gt;  &lt;p&gt;In many of these discussions (not including the posts I referred to) it seems like one aspect of ViewModel get’s lost, which is “Why use it in the first place?” This leads to a lot of debate around details of implementation including one item in particular which is whether or not &lt;a href="http://www.lhotka.net/weblog/InitialThoughtsOnMVVM.aspx"&gt;code in the code-behind&lt;/a&gt; is an anti-pattern. Building off of the stage &lt;a href="http://www.haacked.com/"&gt;Phil&lt;/a&gt; set in his great &lt;a href="http://haacked.com/archive/2009/07/14/law-of-demeter-dot-counting.aspx"&gt;LOD&lt;/a&gt; post, I’ll say ViewModel is not a code-counting exercise.&lt;/p&gt;  &lt;h2&gt;The essence and the spirit&lt;/h2&gt;  &lt;p&gt;John says in his post, “Model/View/ViewModel is a variation of Model/View/Controller (MVC) that is tailored for modern UI development platforms where the View is the responsibility of a designer rather than a classic developer.&amp;#160; The designer is generally a more graphical, artistic focused person, and does less classic coding than a traditional developer.”&lt;/p&gt;  &lt;p&gt;Martin then states in this Bliki that “The essence of a Presentation Model is of a fully self-contained class that represents all the data and behavior of the UI window, but without any of the controls used to render that UI on the screen. A view then simply projects the state of the presentation model onto the glass.” Martin then adds “It's useful for allowing you to test without the UI, support for some form of multiple view and a separation of concerns which may make it easier to develop the user interface.”&lt;/p&gt;  &lt;p&gt;From John’s perspective, it is a pattern that enables a UX designer (non-developer) to be &lt;em&gt;responsible&lt;/em&gt; for the UI. From Martin’s perspective it’s about separation-of-concerns and testability. So which one is right? I say both. Also notice neither one said anything about having zero-code in the code-behind. Instead they spoke about maintainability.&lt;/p&gt;  &lt;p&gt;So what is the spirit of MVVM then? I say it’s building UIs that utilize platform enhancements in WPF and Silverlight to provide good separation between UI and business logic in order to make those UIs easier to maintain by developers and designers. &lt;/p&gt;  &lt;p&gt;When I say designer, I don’t mean only the stereotypical guy/gal who wears a black sweater :-). It may also be a developer who is using Blend/Cider to define the UI, which is likely, as we all know hand coding a ton of XAML is anything but fun.&lt;/p&gt;  &lt;p&gt;Why have I called out WPF and Silverlight? Because the pattern is specific and solely on the specific data binding, data templates, attached properties and command implementations found in the platform. Presentation Model on the other hand is entirely general and places no such specificity. I would not for example recommend ViewModel as an appropriate pattern for ASP.NET or Winforms, but I would however recommend PresentationModel, in addition to MVP, etc.&lt;/p&gt;  &lt;h2&gt;It’s not about counting code&lt;/h2&gt;  &lt;p&gt;They key here (and which I want to touch on) is the last part, “easier to maintain by developers and designers.”. This means (if you buy my definition) that the chosen implementation should consider both aspects of the equation, that is what does it do for the developer and what does it do for the designer. Obviously tradeoffs have to be made, but the key is finding a healthy balance, reducing the negative impact to both.&lt;/p&gt;  &lt;p&gt;Which brings us to the code counting question. Does having zero code in the code-behind make the UI easier to maintain? I say it depends on what kind of code you are talking about:&lt;/p&gt;  &lt;p&gt;If the code is UI level business logic which does not relate directly to the rendering of the view, such as determining whether or not certain elements are visible, or enabled, then I agree, this kind of code is a separate concern and should not appear in the View at all and be within the ViewModel. I would include in this the XAML, as the XAML is still part of the view. Why shouldn’t this logic be there? Because it makes the UI difficult to maintain by creating a tight coupling between the UI and the logic. It makes it difficult to test, and is also very brittle and likely to break as the UI evolves in response to changing requirements.&lt;/p&gt;  &lt;p&gt;On the other side of the coin are UI-specific concerns, I would include in this setting enabled state, visibility or starting/stopping animations as well as even logic that relates to which model data a specific UI element binds to. That may sound contradictory to my previous statement but it is not. What I mean is, the ViewModel should contain the logic to determine whether something is visible or not, and the View should act on that knowledge to then hide the element. Adding this logic to the ViewModel would introduce tight coupling between the ViewModel and the View, this time from the ViewModel side.&lt;/p&gt;  &lt;p&gt;Now being that it is a UI specific concern, the next question is how should it be handled, as code in the code-behind or in XAML? And for that answer I would say it depends on the specific concern itself, as well as whether or not there is a UX designer who handles the UI. Even still,&amp;#160; I would look at an approach that best meets the needs of both developers and designers.&lt;/p&gt;  &lt;h2&gt;Data binding&lt;/h2&gt;  &lt;p&gt;Let’s take data binding as an example. If I am working with a dedicated UX designer then bindings in XAML is the prevalent technique that our tooling provides for data binding. Now it does negatively impact the development team to some degree in that due to XAML’s very loose nature it is very easy to break and difficult to verify and test. However there’s no other option for the designer other than forcing them to write code, which is how should we say less than optimal. &lt;/p&gt;  &lt;p&gt;If there was no UX designer present however, I would see no issue with putting that binding definition in code, even in the code-behind. As developers are used to writing code, not markup, and the developer IDE provides much richer support for developers in code. Now that being said, the API for defining bindings is not really well-suited for doing them in code, but OSS solutions like &lt;a href="http://www.lostechies.com/blogs/gabrielschenker/archive/2009/06/01/fluent-silverlight-part-1.aspx"&gt;“Fluent Silverlight”&lt;/a&gt; help bridge that gap. &lt;/p&gt;  &lt;h2&gt;Animations&lt;/h2&gt;  &lt;p&gt;A different example relates to animations. The user clicks a Save button on the Edit Order screen which requires some UI cue to the user such as an hourglass while the order is saving, and another cue once the Order has saved. The question is where should this logic live? In the XAML or in the code? You could handle this in the XAML by using triggers, attached behaviors and the like. In the case of Silverlight, you don’t yet have triggers yet baked in, but you could look to using those included with &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc721608.aspx"&gt;Blend&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Now although you “could”, I wouldn’t, though you might feel different. The reason goes back to maintainability, having such logic in the view means once again it is easy to break and difficult to test (How do I know it actually works?). Instead, I would opt in this case to separate into two parts, the pure visual part and the logic. The pure visual would be the hour glass animation, and the saved completed screen which could likely be purely defined in XAML. However, the logic part which determines to show the hour glass while saving is in progress would rest in the code. I would achieve this by adding OnSave,OnSaveCompleted methods to the view which would both contain the logic to actually display the elements. &lt;/p&gt;  &lt;p&gt;The ViewModel would get injected with either an interface to the view, or with a set of delegates it could call to once save begins and completes. Yes, I did say I’d put code in the code-behind! That is ok because it is code that relates entirely to a view-level concern. Also I would argue that putting the one line of code in the View, only minimally impacts the designer. They can still verify that the animations works. On the plus side it means that we’re remove one more potential piece of brittle, un-testable logic. Also it improves debugging as a developer can put a break-point on the view methods to and see whether or not they are even getting called, additionally it ensures that an exception is thrown if the animation in question is removed.&lt;/p&gt;  &lt;h2&gt;Commands and Parameters&lt;/h2&gt;  &lt;p&gt;The last thing I want to touch on relates to invoking commands, and usage of command parameters through element binding, vs using bound properties on the ViewModel. The user selects an item in the Order list, and double clicks. Do we a) Use element binding and have clicking on the “Open Order” button invoke the OpenOrder command passing in the currently selected order as a parameter, or b) Set the orders list selected item to bind to a SelectedOrder ViewModel property and then have a parameterless OpenOrder command which uses the SelectedOrder order property on the VM itself. &lt;/p&gt;  &lt;p&gt;I would argue B over A, and why relates back to the maintainability question. If I use element binding, again I make the view harder to maintain. In this case, I haven’t coupled it to the VM, but I have coupled one part of the View to another part of the View. The impact here is on future refactorings of the View. If move around elements in the view such that the relative binding is broken, I broke my UI, if I use the second approach however, I can re-factor / replace elements all day long without breaking any relative bindings. &lt;/p&gt;  &lt;p&gt;Yes, I’ve added properties to the ViewModel, but those properties are easy to discover, and result in UIs that are less prone to break over time. I should also add that using approach B works just as well for a designer, as they can easily bind to the properties on the VM for the parameters and parameterless commands.&lt;/p&gt;  &lt;h2&gt;Conclusion&lt;/h2&gt;  &lt;p&gt;In conclusion, the spirit of MVVM is about producing maintainable UIs for the developer and the designer, not UIs that have zero code. I would recommend folks who are developing using the MVVM pattern to focus less on whether or not there is code in the code behind, and rather focus on the type of code and whether it improves / or hinders the maintainability of the UI. Sometimes having a bit of code in the code behind actually goes a long way toward improving it.&lt;/p&gt;  &lt;p&gt;What are your thoughts on this topic? I’d love to hear them.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9855916" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=zMy8tgdMTtU:GidINz0mnLw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=zMy8tgdMTtU:GidINz0mnLw:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=zMy8tgdMTtU:GidINz0mnLw:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=zMy8tgdMTtU:GidINz0mnLw:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=zMy8tgdMTtU:GidINz0mnLw:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=zMy8tgdMTtU:GidINz0mnLw:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=zMy8tgdMTtU:GidINz0mnLw:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/viewmodel/default.aspx">viewmodel</category><category domain="http://blogs.msdn.com/gblock/archive/tags/MVVM/default.aspx">MVVM</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/08/03/the-spirit-of-mvvm-viewmodel-it-s-not-a-code-counting-exercise.aspx</feedburner:origLink></item><item><title>Stable Composition in MEF Preview 6</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/klrekWoli3s/stable-composition-in-mef-preview-6.aspx</link><pubDate>Sun, 02 Aug 2009 22:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9855762</guid><dc:creator>Glenn Block</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9855762.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9855762</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9855762</wfw:comment><description>&lt;p&gt;&lt;img title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/nblumhardt/WindowsLiveWriter/LightuporMEFOptionalExports_AA58/image_thumb_4.png" width="555" height="330" mce_src="http://blogs.msdn.com/blogfiles/nblumhardt/WindowsLiveWriter/LightuporMEFOptionalExports_AA58/image_thumb_4.png" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/nblumhardt/archive/2009/07/17/light-up-or-mef-optional-exports.aspx" mce_href="http://blogs.msdn.com/nblumhardt/archive/2009/07/17/light-up-or-mef-optional-exports.aspx"&gt;Nick&lt;/a&gt; just posted on a new and very important feature we added in &lt;a href="http://blogs.msdn.com/nblumhardt/archive/2009/07/09/mef-preview-6-available.aspx" mce_href="http://blogs.msdn.com/nblumhardt/archive/2009/07/09/mef-preview-6-available.aspx"&gt;Preview 6&lt;/a&gt; which we call Stable Composition. To give you an idea of why we added this, in the past if you had a part, say OrderProcessor, that had a required import of ILogger, and no logger was present, then composition would fail, and in so doing would corrupt the state of the container. Once that corruption happened, you were basically left with no option but to tear down the container, and in most cases shutdown the application. With Stable Composition the troublesome parts are rejected from the system thus maintaining stability.&lt;/p&gt;  &lt;p&gt;In summary, it basically has two components to it:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, it ensures that only parts whose imports can be satisfied will ever be allowed to enter the system. Those imports might not be satisfied for one of several reasons including the export not being present (Importing ILogger and no loggers are present), or too many exports being present (Importing ILogger and many loggers are present). &lt;strong&gt;Note:&lt;/strong&gt; You can still use the approach described &lt;a href="http://codebetter.com/blogs/glenn.block/archive/2009/05/14/customizing-container-behavior-part-2-of-n-defaults.aspx" mce_href="http://codebetter.com/blogs/glenn.block/archive/2009/05/14/customizing-container-behavior-part-2-of-n-defaults.aspx"&gt;here&lt;/a&gt; to provide defaults in the presence of multiple implementations.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Second&lt;/strong&gt;, this feature ensures that once parts have entered the system, they will never be allowed to enter an invalid state (i.e. their dependency requirements will not be able to be upset). For example if a part in a running system contains an import of a single logger, and one attempts to add a new logger to the catalog/container, then that new logger will be rejected. &lt;/p&gt;  &lt;p&gt;In either case, the effect is to reject such parts and their transitive dependencies, meaning the entire object graph that is problematic is pruned. In Nick’s example, A PointOfSale part imports ItemLookup contracts. ProductLookup depends on ProductRepository which is preset, so it is imported without a problem. ServiceLookup however depends on ServiceRepository which the standard POS SKU does not provide, thus ServiceLookup is rejected. &lt;/p&gt;  &lt;h2&gt;Subtleties of rejection&lt;/h2&gt;  &lt;p&gt;Now having such a feature present has some subtle implications in particular when the hierarchy of dependencies is deep, and the part at the bottom of the chain is rejected. For example, Shell imports Toolbar, and Toolbar imports the ToolbarButtonState service which is missing some dependency for one reason or another, then the Shell itself will be rejected. If you are debugging the application, you might be staring at the debugger dumbfounded when you see the message “No Exports Found” for Shell. The problem has nothing to do with Shell directly, but it is related to one of it’s deep dependencies. &lt;/p&gt;  &lt;p&gt;There are ways to design around this, for example if Toolbar is an optional import on Shell, then Shell will load even if Toolbar is not present. Thus you could check the Toolbar property, determine it is null and throw an exception indicating that there is an issue with the Toolbar or one of it’s dependencies. &lt;/p&gt;  &lt;p&gt;Nick has posted an indispensable tool which he discusses in the Preview 6 &lt;a href="http://blogs.msdn.com/nblumhardt/archive/2009/07/09/mef-preview-6-available.aspx" mce_href="http://blogs.msdn.com/nblumhardt/archive/2009/07/09/mef-preview-6-available.aspx"&gt;post&lt;/a&gt; which analyzes the container to determine which parts have been rejected and why.&amp;#160; Finally in our next drop, Preview 7, (and in Beta 2) you’ll see we’ve added tracing infrastructure that in the debugger will write part rejection messages to the output window. You will also be able to use the tracing to write to a log file at runtime for diagnosing rejection in a deployment environment.&lt;/p&gt;  &lt;p&gt;We are planning further guidance on Stable Composition which will ship with our documentation. &lt;/p&gt;  &lt;p&gt;Check out Nick’s &lt;a href="http://blogs.msdn.com/nblumhardt/archive/2009/07/17/light-up-or-mef-optional-exports.aspx" mce_href="http://blogs.msdn.com/nblumhardt/archive/2009/07/17/light-up-or-mef-optional-exports.aspx"&gt;post&lt;/a&gt; for more details on the feature, and as always feedback is appreciated.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9855762" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=klrekWoli3s:Gy8VxcNwc1E:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=klrekWoli3s:Gy8VxcNwc1E:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=klrekWoli3s:Gy8VxcNwc1E:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=klrekWoli3s:Gy8VxcNwc1E:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=klrekWoli3s:Gy8VxcNwc1E:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=klrekWoli3s:Gy8VxcNwc1E:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=klrekWoli3s:Gy8VxcNwc1E:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/08/02/stable-composition-in-mef-preview-6.aspx</feedburner:origLink></item><item><title>MEF and XAML integration – Self composition</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/VC-NzZyDbgI/mef-and-xaml-integration-self-composition.aspx</link><pubDate>Sat, 18 Jul 2009 11:59:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9838432</guid><dc:creator>Glenn Block</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9838432.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9838432</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9838432</wfw:comment><description>&lt;p&gt;As I am hoping you heard from &lt;a href="http://blogs.msdn.com/nblumhardt/"&gt;Nick&lt;/a&gt;, we just shipped &lt;a href="http://blogs.msdn.com/nblumhardt/archive/2009/07/09/mef-preview-6-available.aspx"&gt;MEF Preview 6&lt;/a&gt; which includes a version of MEF for Silverlight 3! At the same time that we’ve been wrapping up on our .NET 4.0 release, we are busy working on a proper release for Silverlight vNext. The things you see in MEF Preview 6 for SL3 are just the beginning. &lt;/p&gt;  &lt;p&gt;For SL, we are working on among other things, a set of MEF/XAML integration features. One of the problems we want to address is have parts within XAML which are (optimally automatically) composed. That is elements which normally would have to be manually added to the container in the code-behind in order for their imports to be satisfied. For example you drop a control anywhere in XAML that has imports, and it will get composed, regardless of where it sits within the XAML hierarchy. &lt;/p&gt;  &lt;p&gt;In order to do this, we’re exploring a pattern we’re calling “Self composition”, that is an unreachable part (one that the container has no access to) can register itself to get composed. The way this works is the part (UIElement) calls a RegisterForComposition method on it’s load event. Calling the method, forces it to get composed by a host-specific strategy, one which in the case of SL might use an app-wide container, or one that is scoped. The important thing is the grid itself is not coupled to how it is going to get composed. For example, see the sample control below.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/glenn.block/image_5F00_2179E073.png"&gt;&lt;img title="image" border="0" alt="image" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/glenn.block/image_5F00_thumb_5F00_393117D9.png" width="526" height="292" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;CustomGrid is a UserControl and it imports a set of IGridBehavior contracts. It’s using MEF for extensibility, thus the application author can deploy behaviors in the container’s catalog, which the grid will use. &lt;/p&gt;  &lt;p&gt;So why does the grid need to register itself? Can’t it somehow be created from the container, which will then satisfy it’s imports? Short answer, no. First notice it has no Export, so it will not get picked up by a catalog. But second, the grid itself is declared within XAML, much like any other control, thus the XAML &lt;em&gt;parser&lt;/em&gt; is the one who creates it. This would be the case whether it was manually defined within the .XAML file or if the control had been dragged from the toolbox. Thus our only option at that point is to grab the existing instance, and see that it’s imports get satisfied.&lt;/p&gt;  &lt;p&gt;But, can’t we somehow take over the creation of the element from XAML, can we have the parser pass of creation to MEF? Actually the XAML 2.0 parser does provide hooks for factories for doing this, however after investigating, there’s a bunch of “devil is in the details” type issues around us doing this, which prevent us from taking this approach, including significant performance hurdles.&lt;/p&gt;  &lt;p&gt;One option is to consider using markup extensions, for example an {ImportMany} ME that is a service locator that can be used within XAML. This would allow setting a Behaviors Dependency Property to all imports of IGridBehavior. This could work, however it means that every user of the grid, must explicitly specify one or more markup&amp;#160; extensions each time they use the grid, something that is leaky, and very poor from a usability perspective. As a side note, we are actually looking to add Markup Extensions for explicitly specifying imports on Dependency Properties, but that is geared more towards the user of the control vs the author.&lt;/p&gt;  &lt;p&gt;Another option is to consider using attached properties, for example a “Compose” attached property would allow specifying Compose=True on our Grid.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/glenn.block/image_5F00_05F4DE70.png"&gt;&lt;img title="image" border="0" alt="image" src="http://codebetter.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/glenn.block/image_5F00_thumb_5F00_16F90C53.png" width="591" height="40" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Although this is less painful then having to specify all the gory details, it still means that the user of the control must explicitly set this wherever the use it. It means the control author cannot transparently decide to start using MEF without impacting every single XAML file that has ever sited that control. &lt;/p&gt;  &lt;p&gt;Now all that being said, in general we're of mixed feelings on the team on the self-registration approach: &lt;/p&gt;  &lt;p&gt;On the down-side: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Having parts have to compose themselves is a violation of SOC, in an ideal world, a part should never be responsible for telling itself to get compose. It’s generally a bad idea. &lt;/li&gt;    &lt;li&gt;It’s a DRY Violation, my part has imports, yet I still have to “Tell” it to compose itself. &lt;/li&gt;    &lt;li&gt;It poses several challenges relating to lifetime management. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;On the up-side: &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;It allows for components which are instantiated by the runtime (in this case FrameworkElements in XAML), and normally unreachable by the container to be able to leverage MEF. This means frameworks (including our own) and applications can gradually migrate to leverage MEF rather than having to be completely re-written / designed in order to leverage composition.&amp;#160; It also means that you can use MEF where you see fit, regardless of whether the framework infrastructure supports it. &lt;/li&gt;    &lt;li&gt;The pattern can even be extended outside of XAML, for example the same approach could work in Winforms, or ASP.NET Web Forms, or even Mobile. This is possible, because the design relies on a host-specific strategy, thus ASP.NET could provide a per-request container, etc. &lt;/li&gt;    &lt;li&gt;Self-registered parts are not coupled to a specific container instance. It's up to the host strategy to decide the container. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;What do you think? Do the pros outweigh the cons? Or should we hold off on introducing such functionality because it will cause more harm than good? &lt;/p&gt;  &lt;p&gt;Your candid feedback is appreciated.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9838432" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=VC-NzZyDbgI:ArQcYw9Mbvc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=VC-NzZyDbgI:ArQcYw9Mbvc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=VC-NzZyDbgI:ArQcYw9Mbvc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=VC-NzZyDbgI:ArQcYw9Mbvc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=VC-NzZyDbgI:ArQcYw9Mbvc:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=VC-NzZyDbgI:ArQcYw9Mbvc:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=VC-NzZyDbgI:ArQcYw9Mbvc:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/silverlight/default.aspx">silverlight</category><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/XAML/default.aspx">XAML</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/07/18/mef-and-xaml-integration-self-composition.aspx</feedburner:origLink></item><item><title>Meffifying Windows Azure</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/Q5Lv4dfZmmg/meffifying-windows-azure.aspx</link><pubDate>Fri, 03 Jul 2009 20:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9816897</guid><dc:creator>Glenn Block</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9816897.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9816897</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9816897</wfw:comment><description>&lt;P&gt;&lt;A href="http://twitter.com/noopman" mce_href="http://twitter.com/noopman"&gt;Magnus&lt;/A&gt; has been off doing some interesting work around integrating &lt;A href="http://mef.codeplex.com/" mce_href="http://mef.codeplex.com"&gt;MEF&lt;/A&gt; with &lt;A href="http://www.microsoft.com/azure" mce_href="http://www.microsoft.com/azure"&gt;Windows Azure&lt;/A&gt;. The first question you might be asking is Why?&lt;/P&gt;
&lt;P&gt;In his words, he set out to build a template for Windows Azure templates that:&lt;/P&gt;
&lt;LI&gt;enables testability &lt;/LI&gt;
&lt;LI&gt;abstracts away storage &lt;/LI&gt;
&lt;LI&gt;is extensible and easy to evolve during development&lt;/LI&gt;
&lt;P&gt;In the post he shows how to take the RoleManger and expose it through MEF, thereby making it pluggable. He then creates a mock Role Manager for use in his unit tests, thus removing the dependency on all the Azure infrastructure.&lt;/P&gt;
&lt;P&gt;I am guessing this is the first of many posts to come on MEF and Azure. &lt;/P&gt;
&lt;P&gt;For more, check out Magnus post &lt;A href="http://blog.noop.se/archive/2009/07/03/windows-azure-plus-managed-extensibility-framework-mef-true.aspx" mce_href="http://blog.noop.se/archive/2009/07/03/windows-azure-plus-managed-extensibility-framework-mef-true.aspx"&gt;here&lt;/A&gt;. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9816897" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q5Lv4dfZmmg:dwZRPnoi1yQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q5Lv4dfZmmg:dwZRPnoi1yQ:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=Q5Lv4dfZmmg:dwZRPnoi1yQ:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q5Lv4dfZmmg:dwZRPnoi1yQ:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q5Lv4dfZmmg:dwZRPnoi1yQ:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q5Lv4dfZmmg:dwZRPnoi1yQ:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=Q5Lv4dfZmmg:dwZRPnoi1yQ:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/azure/default.aspx">azure</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/07/03/meffifying-windows-azure.aspx</feedburner:origLink></item><item><title>Upcoming talks at NDC in Oslo and Poland</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/NuKc1FlCG-Y/upcoming-talks-at-ndc-in-olso-and-poland.aspx</link><pubDate>Thu, 11 Jun 2009 01:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9725235</guid><dc:creator>Glenn Block</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9725235.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9725235</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9725235</wfw:comment><description>&lt;P&gt;&lt;IMG border=0 alt="" src="http://www.ndc2009.no/images/toppENG.png" width=990 height=118 mce_src="http://www.ndc2009.no/images/toppENG.png"&gt;&lt;/P&gt;
&lt;P&gt;Next week, I am heading to Europe for two weeks to give several talks. My first stop is &lt;A href="http://www.ndc2009.no/en/" mce_href="http://www.ndc2009.no/en/"&gt;NDC 2009&lt;/A&gt;, where I’ll be delivering the following talks:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.ndc2009.no/en/agenda.aspx?#TB_inline?height=600&amp;amp;width=830&amp;amp;inlineId=32940&amp;amp;modal=true" mce_href="http://www.ndc2009.no/en/agenda.aspx?#TB_inline?height=600&amp;amp;width=830&amp;amp;inlineId=32940&amp;amp;modal=true"&gt;Framework Design Guidelines&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.ndc2009.no/en/agenda.aspx?#TB_inline?height=600&amp;amp;width=830&amp;amp;inlineId=32941&amp;amp;modal=true" mce_href="http://www.ndc2009.no/en/agenda.aspx?#TB_inline?height=600&amp;amp;width=830&amp;amp;inlineId=32941&amp;amp;modal=true"&gt;Building Maintainable Enterprise Applications with Silverlight and WPF&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.ndc2009.no/en/agenda.aspx?#TB_inline?height=600&amp;amp;width=830&amp;amp;inlineId=32938&amp;amp;modal=true" mce_href="http://www.ndc2009.no/en/agenda.aspx?#TB_inline?height=600&amp;amp;width=830&amp;amp;inlineId=32938&amp;amp;modal=true"&gt;Building openly extensible applications with .NET Framework 4.0&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;NDC looks like an &lt;STRONG&gt;&lt;EM&gt;amazing&lt;/EM&gt;&lt;/STRONG&gt; event with a great lineup of speakers. I am hoping to be able to attend a few talks so I can soak up all their goodness. All my talks are in one day, so it’s going to be real wild ride!&lt;/P&gt;
&lt;DIV style="TEXT-ALIGN: center"&gt;&lt;A href="http://www.ms-groups.pl/glennblock/"&gt;&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="TEXT-ALIGN: center"&gt;&lt;A href="http://www.ms-groups.pl/glennblock/"&gt;&lt;IMG style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none" align=left src="http://ms-groups.pl/olmug/Obrazy/GlennBlockTourBanner.jpg" mce_src="http://ms-groups.pl/olmug/Obrazy/GlennBlockTourBanner.jpg"&gt;&lt;/A&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Next is on to Poland for a 5 city &lt;A href="http://ms-groups.pl/glennblock/default.aspx" mce_href="http://ms-groups.pl/glennblock/default.aspx"&gt;user group tour&lt;/A&gt; in: &lt;A href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=1" mce_href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=1"&gt;Olsztyn&lt;/A&gt;, &lt;A href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=2" mce_href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=2"&gt;Toruń&lt;/A&gt;, &lt;A href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=3" mce_href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=3"&gt;Warszawa&lt;/A&gt;, &lt;A href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=4" mce_href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=4"&gt;Kraków&lt;/A&gt;, &lt;A href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=5" mce_href="http://ms-groups.pl/glennblock/Lists/Glenn%20Block%20Tour/DispForm.aspx?ID=5"&gt;Katowice&lt;/A&gt; where I’ll be speaking about building extensible apps, or other topics if folks attending would like (comment to this post if you have other topics)&lt;/P&gt;
&lt;P&gt;If you are attending NDC or will be in any of the cities mentioned, I look forward to chatting with you about how we can build better software!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9725235" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=NuKc1FlCG-Y:RNdv5iixOu8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=NuKc1FlCG-Y:RNdv5iixOu8:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=NuKc1FlCG-Y:RNdv5iixOu8:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=NuKc1FlCG-Y:RNdv5iixOu8:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=NuKc1FlCG-Y:RNdv5iixOu8:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=NuKc1FlCG-Y:RNdv5iixOu8:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=NuKc1FlCG-Y:RNdv5iixOu8:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/Conference/default.aspx">Conference</category><category domain="http://blogs.msdn.com/gblock/archive/tags/silverlight/default.aspx">silverlight</category><category domain="http://blogs.msdn.com/gblock/archive/tags/prism/default.aspx">prism</category><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/06/10/upcoming-talks-at-ndc-in-olso-and-poland.aspx</feedburner:origLink></item><item><title>Customizing container behavior part 2 of N - Defaults</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/1AbeE8ys-iU/customizing-container-behavior-part-2-of-n-defaults.aspx</link><pubDate>Thu, 14 May 2009 11:14:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9615143</guid><dc:creator>Glenn Block</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9615143.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9615143</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9615143</wfw:comment><description>&lt;p&gt;Before I get into the post, let me start off with a word of advice for new bloggers. Never say in a post, this is the first of many to come. RESIST! You are just setting yourself up for never doing that second post. I know as the last post in this series was five months ago. ;-)&lt;/p&gt;  &lt;p&gt;In the last &lt;a href="http://codebetter.com/blogs/glenn.block/archive/2008/12/25/using-exportprovider-to-customize-container-behavior-part-i.aspx"&gt;post,&lt;/a&gt; I introduced the concept of ExportProviders as a way to customize how the CompositionContainer discovers exports. One of the primary use cases for doing this is to provide default exports, which is particularly important for cases where you are importing a single value for which there are multiple present. The common case I like to use is the overused Logger example. Let’s say you have multiple loggers in the system, which are used for different functions. One logger logs locally, while others can log remotely perhaps invoking a web service, or using MSMQ. These loggers are all pluggable, as different organizations that use the app may have different needs. Each of these loggers export an ILogger contract.&lt;/p&gt;  &lt;p&gt;Now most of the time when logging occurs the local logger is sufficient. It’s only exceptions to the rule that require the special loggers. And this is where you run into a problem. How do you specify that you need to import that default logger, where there are multiple present? In the default configuration of MEF, the only way to really handle this if you are using imports is to either create a specialized contract for the default logger say IDefaultLogger which is imported, or to import the entire collection lazily using Export&amp;lt;ILogger&amp;gt; and then looking at the metadata for each to find the right one. You could also create a custom service called LoggerService, which imports all the loggers finds the default one, and then returns it when LoggerService.DefaultLogger is called. None of these are optimal though. &lt;/p&gt;  &lt;p&gt;For example, you could do this….&lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Export&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;LoggerManager &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;ILoggerManager
&lt;/span&gt;{
    [&lt;span style="color: #2b91af"&gt;ImportingConstructor&lt;/span&gt;]
    &lt;span style="color: blue"&gt;public &lt;/span&gt;LoggerManager(&lt;span style="color: #2b91af"&gt;Export&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;ILogger&lt;/span&gt;,&lt;span style="color: #2b91af"&gt;ILoggerMetadata&lt;/span&gt;&amp;gt;[] loggers)
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;logger = loggers.Single(e =&amp;gt; e.MetadataView.IsDefault==&lt;span style="color: blue"&gt;true&lt;/span&gt;);
        DefaultLogger = logger.GetExportedObject();
    }
    
    &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ILogger &lt;/span&gt;DefaultLogger { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;private set&lt;/span&gt;;}

}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The problem is this means the LoggerManager has to have hard knowledge of which logger is the default. It also means the logger itself needs to somehow declare that it is the default, which is problematic because one logger might be the default in one app, but not in another. Separation of concerns anyone? Even worse you might have two loggers that say they are the default!&lt;/p&gt;

&lt;p&gt;Now there are other mental hoops you can jump through to find a workable solution, but it’s a lot of pain when what you really want you want to do is tell MEF’s container somehow “This is my default logger for this application”. Not only that but you want to do it in a way that does not require the app to hardcode it, does not require explicit configuration, nor does it require the parts to somehow ‘tell’ MEF they are the default. Also you don’t want the parts that are importing ILogger to have to know or care about a LoggerManager or anything like that. Instead they should simply have an import of ILogger.&lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;Export&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Executor
&lt;/span&gt;{
    [&lt;span style="color: #2b91af"&gt;ImportingConstructor&lt;/span&gt;]
    &lt;span style="color: blue"&gt;public &lt;/span&gt;Executor(&lt;span style="color: #2b91af"&gt;ILogger &lt;/span&gt;logger)
    {
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The $25000 question is how? The answer is using our friendly ExportProvider. In my last post I described the role of ExportProviders, which is to simply return exports. Those exports can come from several different sources, including from catalogs.&lt;/p&gt;

&lt;h1 align="left"&gt;Constructing the container with ExportProviders&lt;/h1&gt;

&lt;p&gt;If you look on the constructor of the container, you’ll see several overloads which accept an ExportProvider.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CompositionContainer(&lt;span style="color: #0000ff"&gt;params&lt;/span&gt; ExportProvider[] providers);&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CompositionContainer(ComposablePartCatalog catalog, &lt;span style="color: #0000ff"&gt;params&lt;/span&gt; ExportProvider[] providers);  &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Any export providers passed in to the container are incorporated into the container’s query strategy. This means whenever anyone pulls on the container for an export, these providers will also get queried. Now catalogs have a special provider associated with them called a CatalogExportProvider. As a matter of fact the overload on the container that accepts a catalog is really just syntactic sugar. Behind the scenes we immediately create a CatalogExportProvider passing in the catalog. This means you can pass in an additional default catalog. If you’ve worked with MEF before, you might be shaking your head at this point and thinking “How is this any different than just having an AggregateCatalog and adding two catalogs?” And that IS the key question ;-). &lt;/p&gt;

&lt;p&gt;The answer is that adding catalogs to an AggregateCatalog does not allow handling defaults, however using this technique with ExportProviders &lt;strong&gt;does&lt;/strong&gt;. I’ll explain how next.&lt;/p&gt;

&lt;h1 align="left"&gt;AggregateCatalogs vs AggregateExportProvider&lt;/h1&gt;

&lt;p&gt;AggregateCatalog is a catalog that contains a list of catalogs. It is a composite pattern, so querying the parent, queries all the children. This is especially useful when you have parts that are “built in” to the application which are added via an AssemblyCatalog, and other parts which are discovered through a DirectoryCatalog. You can add both catalogs to an AggregateCatalog and everything works nicely. It doesn’t help you though in a default scenario however. The reason is because if one of your catalogs contains your default ILogger and your other catalogs contain the pluggable ILogger implementations, then the aggregate catalog will return them all when it is queried. This means the Executor above will blow up as the constructor is expecting a single ILogger. &lt;/p&gt;

&lt;p&gt;For the AggregateExportProvider however, we designed specifically to allow this defaults scenario to be addressed. The provider behaves differently depending on whether it is being queried for a single export or multiple. If the query is for multiple exports, then it works similar to the AggregateCatalog and collects all the exports it finds in any of it’s providers. If on the other hand the query is for a single export, then it uses a prioritization scheme. It will start at the top of the list of ExportProviders and query the first one for the single export (Logger). If it does not find one, then it keeps querying on to the next ExportProvider and so on. Once it finds an ExportProvider that returns one, then it will be returned, if it does not find one, then it will throw an exception.&lt;/p&gt;

&lt;p&gt;This means you can have default ExportProviders in the chain (including CatalogExportProviders) that contain your defaults so that the Executor class always succeeds in creation. You can even configure the behavior so that the defaults are overridable or not. For example if you want the default ILogger to always be the logger that is returned for all single import queries no matter what, then put the defaults at the top of the chain. If however you want the default logger to be overridable by another single ILogger, then put it at the end.&lt;/p&gt;

&lt;p&gt;Here’s an illustration of what I mean.&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OverridableDefaults()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var catalog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DirectoryCatalog(&lt;span style="color: #006080"&gt;@&amp;quot;.\Extensions&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var defaultCatalogEP = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CatalogExportProvider(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DirectoryCatalog(&lt;span style="color: #006080"&gt;@&amp;quot;.\Defaults&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var container = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CompositionContainer(catalog, defaultCatalogEP);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    defaultCatalogEP.SourceProvider = container;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In the configuration above, we are placing our defaults at the end of the chain of providers. Remember as&amp;#160; I mentioned above that the ‘catalog’ reference will get wrapped in a CatalogExportProvider as well. It will get added first, followed by the additional providers. We then have to set the SourceProvider to the container, I talked about why this is necessary today in my previous &lt;a href="http://codebetter.com/blogs/glenn.block/archive/2008/12/25/using-exportprovider-to-customize-container-behavior-part-i.aspx"&gt;post&lt;/a&gt;, though it may be possible for us to infer the setting in the future. Anyway, now when a query happens for a single logger, the container will first check the parts in the Extensions folder, and if none are found it will revert to the defaults. &lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; NonOverridableDefaults()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var defaultCatalog = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DirectoryCatalog(&lt;span style="color: #006080"&gt;@&amp;quot;.\Defaults&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var catalogEP = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CatalogExportProvider(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DirectoryCatalog(&lt;span style="color: #006080"&gt;@&amp;quot;.\Extensions&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var container = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CompositionContainer(defaultCatalog, catalogEP);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    catalogEP.SourceProvider = container;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In this example, we are passing in the default catalog first, and then passing the catalog (as an EP). This configuration now means that the defaults are NEVER overridable, as whenever the container is queried for a single logger, it will ALWAYS return the default.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;h1 align="left"&gt;Using Type or Assembly Catalogs for defaults&lt;/h1&gt;

&lt;p&gt;Now in the approach above we are using DirectoryCatalogs for specifying defaults. But remember, this is an option, you don’t have to, and in many cases might not want to. For example you might want to just specify your list of defaults in code, or even in a config file. TypeCatalog provides a great way to do this. (It accepts a params of Types, so you can add as many as you want).&lt;/p&gt;

&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;
  &lt;div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;
    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OverridableDefaultsWithTypeCatalog()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;{&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var catalogEP = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CatalogExportProvider(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DirectoryCatalog(&lt;span style="color: #006080"&gt;@&amp;quot;.\Extensions&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var defaultCatalogEP = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CatalogExportProvider(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TypeCatalog(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt; (ILogger)));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    var container = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CompositionContainer(catalogEP, defaultCatalogEP);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &amp;#39;Courier New&amp;#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;}&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;OK, so now that you sold me, what are the caveats?&lt;/h1&gt;

&lt;p&gt;As with all things, there are some. Really, I can only think of one primary one, and that is that there’s still a bit of indeterminism as to what will get returned on a single import depending on how you set up the provider chain. If you go with the approach of putting defaults first, then it is completely deterministic. You know that whenever a single import request is issued to the container, the exports in that catalog will be returned, period. If however you arrange the defaults at the end of the chain, then it really depends on what is in the middle. Let’s say you have 3 EPs, and the one in the middle has a part with the single export that you are looking for, while you also have a default. In that case the one in the middle will get returned. Another caveat might be that this does add a bit of complexity, however I would argue that’s a reasonable trasdeoff to having to import collections all over the place.&lt;/p&gt;

&lt;h1&gt;The code&lt;/h1&gt;

&lt;p&gt;You can download sample code that illustrates using ExportProviders in various fashions &lt;a href="http://cid-f8b2fd72406fb218.skydrive.live.com/self.aspx/blog/MEF%20Export%20Provider%20Tests%20.zip"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you look inside, you’ll find much more than just what we covered here.&amp;#160; Including how to do do role based composition, or even wire MEF to a configuration store where config info is an import. All of this will get covered at some point.&lt;/p&gt;

&lt;p&gt;Additionally:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;You’ll find several test classes which are using a context/specification style of testing to illustrate how to use ExportProviders.&amp;#160; If you are not familiar with BDD/CS it may seem very foreign, but I think you’ll find it easy to follow once the initial shock wears off. Having gone through this experience made me a big fan of CS style, and that is for another post. &lt;/li&gt;

  &lt;li&gt;You’ll find several test helper classes I’ve written specifically for MEF. These are really useful for folks writing their own ExportProviders and who wish to mock / fake certain parts of our programming model. Specifically I am talking about FakeExportDefinition and FakeExportProvider. Additionally you’ll see some common classes I’ve used for my own CS experiments. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For stuff relating to what was covered in this post, go check out the Import_Logger_Specs.cs unit-tests.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Special thanks to &lt;/strong&gt;&lt;a href="http://blog.scottbellware.com/"&gt;Scott Bellware&lt;/a&gt;&lt;strong&gt; as well as &lt;a href="http://www.scottcreynolds.com/"&gt;Scott C. Reynolds&lt;/a&gt; and &lt;a href="http://twitter.com/davidmfoley"&gt;David Foley&lt;/a&gt; who invested a lot of time and effort in getting me off the ground in using this style of testing. &lt;/strong&gt;Without their help, I would have been stranded in a pool of confusion. This post is really not doing CS justice, and I really need a separate series. I can’t guarantee that I’ll get to it, but I’ll try.&lt;/p&gt;

&lt;h2&gt;What’s next&lt;/h2&gt;

&lt;p&gt;In the next post we’ll talk about establishing parent-child containers hierarchies. You may be asking how does this relate to ExportProviders? I’ll leave you with this thought to ponder, our container &lt;strong&gt;IS&lt;/strong&gt; an ExportProvider.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&amp;#160;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9615143" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=1AbeE8ys-iU:hNZ3DxvSFfc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=1AbeE8ys-iU:hNZ3DxvSFfc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=1AbeE8ys-iU:hNZ3DxvSFfc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=1AbeE8ys-iU:hNZ3DxvSFfc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=1AbeE8ys-iU:hNZ3DxvSFfc:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=1AbeE8ys-iU:hNZ3DxvSFfc:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=1AbeE8ys-iU:hNZ3DxvSFfc:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/Export+Providers/default.aspx">Export Providers</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/05/14/customizing-container-behavior-part-2-of-n-defaults.aspx</feedburner:origLink></item><item><title>“View Model” - the movie, cast your vote.</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/ZOADHQkUkCo/view-model-the-movie-cast-your-vote.aspx</link><pubDate>Tue, 05 May 2009 06:58:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9587480</guid><dc:creator>Glenn Block</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9587480.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9587480</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9587480</wfw:comment><description>&lt;p&gt;&lt;img title="" alt="Star Wars Script by Richard Moross." src="http://farm4.static.flickr.com/3159/3064808115_6f73ec874d.jpg?v=0" width="375" height="500" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.flickr.com/photos/richardmoross/3064808115/" href="http://www.flickr.com/photos/richardmoross/3064808115/"&gt;http://www.flickr.com/photos/richardmoross/3064808115/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;No we’re not actually making a movie about View Model. If we were I am sure we’d get a low turn-out. :-) However it did get your attention.&lt;/p&gt;  &lt;p&gt;What we are doing is some serious exploration into how we can help from a platform perspective folks that are implementing ViewModel (AKA &lt;a href="http://blogs.msdn.com/johngossman/archive/2005/10/08/478683.aspx"&gt;Model-View-ViewModel&lt;/a&gt;&amp;#160; AKA &lt;a href="http://martinfowler.com/eaaDev/PresentationModel.html"&gt;Presentation Model&lt;/a&gt;)&amp;#160; in their Silverlight and WPF applications.&lt;/p&gt;  &lt;p&gt;In the sense of a movie production, we’re in the script-writing phase. Here’s the general background.&lt;/p&gt;  &lt;h2&gt;Why is ViewModel important?&lt;/h2&gt;  &lt;p&gt;There have been many a post on the importance of ViewModel as a pattern and the benefits it brings. In that there is little disagreement that it benefits &lt;em&gt;both&lt;/em&gt; &lt;em&gt;&lt;u&gt;developers&lt;/u&gt;&lt;/em&gt; and &lt;em&gt;&lt;u&gt;designers&lt;/u&gt;.&lt;/em&gt; &lt;/p&gt;  &lt;p&gt;For developers it allows them to have clean separation of presentation logic from the UI rendering, thus making the app easier to maintain. It removes code from the code-behind that often makes the UI logic difficult to test.&lt;/p&gt;  &lt;p&gt;For designers it provides a way for a designer to completely change the look of the UI in a tool such as Expression Blend, without breaking the application functionality. Furthermore it gives the designer freedoms beyond simple look and feel, to actually decide which data elements are exposed, as well as defining the interactions between the UI elements through commands and attached behaviors.&lt;/p&gt;  &lt;h2&gt;The debate over roles&lt;/h2&gt;  &lt;p&gt;Although the benefits of ViewModel are known, there’s quite a lot of debate both inside and outside Microsoft on the roles the developer and designer play in developing applications that use the pattern.&amp;#160; This runs the spectrum from the designer having complete control of every aspect of the UI,&amp;#160; to the development team having more of a tight handle on the UI components, and the designer being responsible for skinning. In either case there are tradeoffs.&lt;/p&gt;  &lt;h2&gt;What is important to you?&lt;/h2&gt;  &lt;p&gt;What is your experience with ViewModel today?&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Where does the platform help,? Where does it hinder? &lt;/li&gt;    &lt;li&gt;What can we do in the platform to make life easier? &lt;/li&gt;    &lt;li&gt;What role do developers / designers play in your application of ViewModel. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Like any movie, we need to touch on the right nerves in order to make it a box-office hit. We need your feedback so we can complete the script. &lt;/p&gt;  &lt;p&gt;Thanks for your help&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9587480" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=ZOADHQkUkCo:mKlCbYORSMs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=ZOADHQkUkCo:mKlCbYORSMs:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=ZOADHQkUkCo:mKlCbYORSMs:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=ZOADHQkUkCo:mKlCbYORSMs:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=ZOADHQkUkCo:mKlCbYORSMs:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=ZOADHQkUkCo:mKlCbYORSMs:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=ZOADHQkUkCo:mKlCbYORSMs:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/silverlight/default.aspx">silverlight</category><category domain="http://blogs.msdn.com/gblock/archive/tags/viewmodel/default.aspx">viewmodel</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/05/05/view-model-the-movie-cast-your-vote.aspx</feedburner:origLink></item><item><title>MEF Preview 5, changes and enhancements</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/Q_jMNj4V51o/mef-preview-5-changes-and-enhancements.aspx</link><pubDate>Sun, 12 Apr 2009 09:10:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9546205</guid><dc:creator>Glenn Block</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9546205.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9546205</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9546205</wfw:comment><description>&lt;p&gt;We recently shipped &lt;a href="http://mef.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25797"&gt;MEF preview 5&lt;/a&gt; on &lt;a href="http://mef.codeplex.com/"&gt;Codeplex&lt;/a&gt;, an exciting release.&lt;/p&gt; &lt;p&gt;In the latest release, you’ll find we’ve made quite a few changes, and some really powerful enhancements to our previous codebase. In this post, I’ll talk about those changes in detail, and why we made them. I’ll also discuss some changes we will be making in the future, in order to give you a heads up, so that you can adjust your code bases now. &lt;/p&gt; &lt;p&gt;Throughout the development of preview 5, we’ve done our best to minimize the impact to you. There are some breaking changes, primarily in terms of namespace refactoring, most of which do &lt;b&gt;not&lt;/b&gt; effect part authors, but will effect MEF hosters, and authors of custom programming models or export providers. &lt;/p&gt; &lt;p&gt;Here’s a summary of these changes for those who want to just cut to the chase. For those who want the full skinny, that comes after the summary.&lt;/p&gt; &lt;table border="1" cellspacing="0" cellpadding="0" width="800"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;&lt;b&gt;Change&lt;/b&gt;&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;p&gt;&lt;b&gt;Summary description&lt;/b&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt;New sample application, MEF Studio&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;We have included a new sample application which is a mock pluggable IDE using MEF.&lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;Namespace changes&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;System.ComponentModel.Composition – For part authors  &lt;li&gt;System.ComponentModel.Composition.Hosting – For hosters  &lt;li&gt;System.ComponentModel.Composition.Primitives – Infrastructure for defining programming models  &lt;li&gt;System.ComponentModel.Composition.ReflectionModel – Services for implementers of catalog caches, and for reflection based programming models. &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;Part Discovery Model and Lifetime Changes&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;CompositionOptions has been removed  &lt;li&gt;New PartCreationPolicyAttribute&amp;nbsp; for specifying part lifetime (Replaces CompositionOptionsAttribute.CreationPolicy )  &lt;li&gt;Exports are not discovered on base classes by default  &lt;li&gt;New PartNotDiscoverable attribute for specifying that a part should not be discovered by the catalog. (replaces [CompositionOptions(DiscoveryMode = DiscoveryMode.Never)])  &lt;li&gt;New PartExportsInherited attribute allows a base class / interface to declare itself as discoverable by inheritors. (replaces [CompositionOptions(DiscoveryMode = DiscoveryMode.Always)] ) &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;Collection Imports&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;New ImportManyAttribute replaces ImportAttribute on collections in the future.  &lt;li&gt;Array imports are now supported &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;Typed Import/Exports&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;Imports and Exports now match on type as well as contract.  &lt;li&gt;Exporters of string contracts such&amp;nbsp; as [Export(“Foo”)] must now specify the type they expect to be imported as well. e.g. [Export(“Foo”, typeof(string))] &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;Custom delegates&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;Method exports can now use custom delegates in addition to Action and Func &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;Directory Catalog changes&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;DirectoryCatalog no longer has watching functionality. We’ve added a Refresh() method for explicit refresh. &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt; &lt;p&gt;Removal of caching / new infrastructure&lt;/p&gt;&lt;/td&gt; &lt;td valign="top" width="538"&gt; &lt;ul&gt; &lt;li&gt;Old caching infrastructure has been ripped. We’ve added a new more general purpose API that is more flexible, and supports builders of custom programming models. We are not shipping a default caching implementation of that API in the box, but one is available in our samples. &lt;/li&gt;&lt;/ul&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="260"&gt;&amp;nbsp;&lt;/td&gt; &lt;td valign="top" width="538"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;h2&gt;&lt;span style="background: white; color: black"&gt;MEF Studio&lt;/h2&gt; &lt;p&gt;MEF Studio is a designer hosting sample. It has an IDE that hosts various designers like Windows Forms, UserControl, etc. One can add controls on to these designers from the toolbox, set properties using the property grid, view generated code, etc. It provides design time experience for the designers and has extension points for extending the adding custom parts.&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt; &lt;h2&gt;&lt;a href="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/MEFPreview5changesandenhancements_ADC0/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/MEFPreview5changesandenhancements_ADC0/image_thumb.png" width="585" height="435"&gt;&lt;/a&gt; &lt;/h2&gt; &lt;h2&gt;Migrating from preview 4&lt;/h2&gt; &lt;p&gt;When you upgrade your existing apps, you will likely run into a few issues. &lt;a href="http://weblogs.asp.net/whaggard/"&gt;Wes&lt;/a&gt; put together the following useful list of common errors that you might run into when migrating.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;System.ComponentModel.Composition.Container does not exist -&amp;gt; Add reference to System.ComponentModel.Composition.Hosting namespace  &lt;li&gt;CompositionContainer does not container method AddPart or Compose -&amp;gt; Need to start using CompositionBatch, or one of the helper extension methods ComposeParts or ComposeExportedObjects  &lt;li&gt;CompositionOptionsAttribute does not exist -&amp;gt; For CreationPolicy use PartCreationPolicyAttribute  &lt;li&gt;INotifyImportCompleted does not exist -&amp;gt; Use IPartImportsSatisfiedNotification interface and change method from ImportCompleted to OnImportsSatisfied &lt;/li&gt;&lt;/ul&gt; &lt;h2&gt;Part Lifetime changes&lt;/h2&gt; &lt;p&gt;Previously, the CreationPolicy property of the CompositionOptions attribute was used to declare a part’s lifetime. We found this was less discoverable for customers as they have to know about the existence of the attribute. We also found that CreationPolicy was ambiguous in name, as it does not make clear whether or not the policy applies to the part or the export.&lt;/p&gt; &lt;p&gt;With the new changes, you will use the new PartCreationPolicyAttribute. CompositionOptions has been removed. Having part in the name of the attribute makes it easier to discover, and also removes ambiguity as to it’s scope.&lt;/p&gt; &lt;p&gt;Below the Logger class is declared as shared:&lt;/p&gt;&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;PartCreationPolicy&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;CreationPolicy.Shared&lt;/span&gt;&lt;span style="background: white; color: black"&gt;)]
[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ILogger&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Logger &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ILogger
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}&lt;/span&gt;&lt;/pre&gt;
&lt;h2&gt;Part Discovery / Inheritance&lt;/h2&gt;
&lt;p&gt;In MEF Preview 4, a part by default would be discovered if there was an export on the most derived class. Additionally a part author could decorate the part with the CompositionOptions attribute, and set the DiscoveryMode property to change the behavior. Regardless of which mode was chosen, we would always look at all exports in the inheritance chain and discover them once we determined a part was a part. 
&lt;p&gt;We heard quite a bit of feedback both internally and externally around both the naming of the different enum values for DiscoveryModel, and the resulting behavior. 
&lt;h3&gt;Default Behavior&lt;/h3&gt;
&lt;p&gt;By default we will only look only at the most derived type to discover exports. If exports are found, then we will do a deep dive to discover all imports wherever they live in the hierarchy, &lt;em&gt;including interface members. &lt;/em&gt;This is because imports are an implementation detail of a part, and the part many not function without them. 
&lt;p&gt;In the example, we will discover a single export of IOrderScreen, and the OrderList import.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public abstract class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;OrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
 [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
 &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderListView &lt;/span&gt;&lt;span style="background: white; color: black"&gt;OrderList { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }
}

[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;NorthwindOrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;OrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Below, we will not discover anything, as the export is on the base. &lt;/p&gt;&lt;span style="background: white; color: black"&gt;&lt;font face="Courier New"&gt;&lt;/font&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public abstract class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;OrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}

&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;NorthwindOrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;OrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
 [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
 &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderListView &lt;/span&gt;&lt;span style="background: white; color: black"&gt;OrderList { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }
}&lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Inherited exports behavior – using the PartExportsInheritedAttributed&lt;/h3&gt;
&lt;p&gt;The PartExportsInherited attribute allows declaring on a base class or an &lt;strong&gt;interface&lt;/strong&gt; that it’s exports should be discovered by inheritors / implementers. This replaces the previous [CompositionOptions(DiscoveryMode = DiscoveryMode.Always)]. This basically allows you to define a template for a part, and is useful hiding MEF’s implementation details from a part author. Implementers can further extend on what has been provided, such as adding their own exports and imports. 
&lt;p&gt;There’s a few guidelines / caveats to using this feature. 
&lt;ul&gt;
&lt;li&gt;PartExportsInheritedAttribute only makes the exports of the type it decorates discoverable by inheritors. It does not make exports of derivers of that type discoverable. The deriver itself needs to be decorated in order to make its exports discoverable. 
&lt;li&gt;We will ignore loose ExportMetadata attributes (and custom metadata attributes) that do not have an associated export. 
&lt;li&gt;If an inheritor overrides a member from the base which has an export, and decorates the overridden member with an export, two exports will be discovered,&lt;em&gt; even if the contract names are the same. &lt;/em&gt;This means if you expect implementers to add their own metadata, this might not be the best option, or at least you will need to provide special handling. We are looking into changing this behavior to have the inheritor override rather than be additive.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;In the example below, NorthwindOrderScreen will automatically export IOrderScreen.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;PartExportsInherited&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public interface &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}

&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;NorthwindOrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}&lt;/pre&gt;&lt;p&gt;&lt;span style="background: white; color: black"&gt;Below NorthwindOrderScreen exports 2 instances of IOrderScreen, one with metadata and one without. The explicit export of IOrderScreen by NorthwindOrderScreen is in addition to the existing export.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;PartExportsInherited&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]&lt;br&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]&lt;br&gt;&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public interface &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen&lt;br&gt;&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{&lt;br&gt;}&lt;br&gt;&lt;br&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ExportMetadata&lt;/span&gt;&lt;span style="background: white; color: black"&gt;("Customer", "Northwind"]&lt;br&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]&lt;br&gt;&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;NorthwindOrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;:&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen&lt;br&gt;&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{&lt;br&gt;}&lt;br&gt;&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;h3&gt;Ignoring part discovery – Using the PartNotDiscoverableAttribute&lt;/h3&gt;&lt;p&gt;This attribute replaces replaces [CompositionOptions(DiscoveryMode.Never).&amp;nbsp; It is useful for when a part author has parts that they do not want to be automatically discovered by catalogs and .&amp;nbsp; The scenarios where this make sense are where you either have a part which you will manually compose outside of a catalog, or you have a part that you intend for inheritors to use in a catalog but which cannot be made abstract. &lt;p&gt;In the sample below,&amp;nbsp; class OrderScreen will be ignored by the catalog. However, when class NorthwindOrderScreen is scanned, we will discover IOrderScreen, and will satisfy the OrderList import.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;PartNotDiscoverable&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;PartExportsInherited&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;OrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
 [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
 &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOrderListView &lt;/span&gt;&lt;span style="background: white; color: black"&gt;OrderList { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }
}

&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;NorthwindOrderScreen &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;OrderScreen
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}&lt;/span&gt;&lt;/pre&gt;&lt;h2&gt;Changes to collection imports&lt;/h2&gt;&lt;h3&gt;ImportMany attribute&lt;/h3&gt;&lt;p&gt;We’ve added a new [ImportMany] attribute. This attribute is to be used for specifying that an importer is expected to import all parts that match the contract. This attribute is equivalent to using [Import] on collections today. By our next release however, [Import] will change to mean import an exported collection. &lt;p&gt;Once we make the switch, the [ImportMany] attribute will be required on both properties and importing constructor parameters in order to get the same behavior as today.&lt;p&gt;As an example let’s take an importer of a collection of IOperation contacts. &lt;p&gt;With the new build the following will have identical results.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOperation&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;gt; Operations { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }

[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ImportMany&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IEnumerable&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOperation&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;gt; Operations { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;In the next drop,&amp;nbsp; the behavior of the first will change. Instead of importing all exports of IOperation, it will instead be looking for an exporter of IEnumerable&amp;lt;IOperation&amp;gt;. The main reason for this is to support custom collections. Today for example the following code won’t yield the expected results if IRepository&amp;lt;T&amp;gt; is an ICollection&amp;lt;T&amp;gt;.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IRepository&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Customer&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;gt; Customers { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;What the part author is intending here is to import a repository of customers. The repository as a whole is the import. Instead what will happen today is the container will set Customers to a new instance of Repository&amp;lt;Customer&amp;gt;. It will then query for all the Customer exports and add them to the Repository.&lt;h3&gt;Array imports&lt;/h3&gt;&lt;p&gt;In this release we’ve added support for array imports.&amp;nbsp; This allows the following syntax to be supported.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ImportMany&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOperation&lt;/span&gt;&lt;span style="background: white; color: black"&gt;[] Operations { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }&lt;/span&gt;&lt;/pre&gt;&lt;h3&gt;&lt;a name="_Toc226739122"&gt;Future Deprecation of ExportCollection&amp;lt;T&amp;gt; and ExportCollection&amp;lt;T,M&amp;gt;&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;In the next preview (not this one) we will be removing ExportCollection from MEF. The reasoning is that ExportCollection does not introduce any additional functionality, and we don’t want to introduce a collection which is solely there for syntactic sugar. The alternative recommended syntax for doing ExportCollection will be to use the new array support. Using the new syntax is significantly more compact than using ExportCollection, and is also less cryptic as arrays are very clear as to how they function.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ImportMany&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOperation&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;gt;[] Operations { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }

[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ImportMany&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOperation&lt;/span&gt;&lt;span style="background: white; color: black"&gt;, &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;IOperationMetadata&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;gt;[] Operations { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Additionally we support custom derived collections, thus you can easily create your own collections that provide the sugar.&lt;h2&gt;Typed Import/Exports&lt;/h2&gt;&lt;p&gt;In Preview 4, MEF discovers exports based on contract name, and not based on the type of the exporter. This means that an export can actually have an incompatible type with the importer. At the time when the export is set on the import, if the cast fails, then an exception is thrown. &lt;p&gt;This new feature in Preview 5 enables MEF to match imports and exports on contract AND type. When a part imports a contract, it additionally specifies the specific type that it is looking for. Only those exporters that also match on the importer type are matched. This means instead of failing, if the exporter’s type is incompatible, then it will not be matched. &lt;p&gt;In most cases, the type specification is done implicitly, and does not require any work on the part of the part author. The overloads of Export and Import that used to take Type as param, will now in addition to converting to the string contract representation, also embed the type information.&lt;p&gt;For example the code below works as it would have before.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Editor
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
 [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
 &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker &lt;/span&gt;&lt;span style="background: white; color: black"&gt;SpellChecker { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }
}

[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;SpellChecker &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;However code that uses pure string contracts, will yield a different result than it would have before. The SpellChecker below will not be imported into the Editor. &lt;/p&gt;&lt;span style="background: white; color: black"&gt;&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Editor
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
 [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #a31515"&gt;"SpellChecker"&lt;/span&gt;&lt;span style="background: white; color: black"&gt;)]
 &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker &lt;/span&gt;&lt;span style="background: white; color: black"&gt;SpellChecker { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }
}

[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #a31515"&gt;"SpellChecker"&lt;/span&gt;&lt;span style="background: white; color: black"&gt;)]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;SpellChecker &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Although SpellChecker implements ISpellChecker the type that the export carries is SpellChecker. The importer on the other hand is of type ISpellChecker so they do not match. In order to make the above code work, the export needs to specify the type.&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #a31515"&gt;"SpellChecker"&lt;/span&gt;&lt;span style="background: white; color: black"&gt;,&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;SpellChecker &lt;/span&gt;&lt;span style="background: white; color: black"&gt;: &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;This works as long as the type of the importer is ISpellChecker. Another option is for the importer to lift the restriction altogether by specifying the type as object.&lt;/p&gt;&lt;font face="Courier New"&gt;&lt;/font&gt;&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Editor
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
 [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Import&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #a31515"&gt;"EditorContracts.SpellChecker"&lt;/span&gt;&lt;span style="background: white; color: black"&gt;,&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;object&lt;/span&gt;&lt;span style="background: white; color: black"&gt;))]
 &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: black"&gt;EditorContracts.&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ISpellChecker &lt;/span&gt;&lt;span style="background: white; color: black"&gt;SpellChecker { &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;get&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;set&lt;/span&gt;&lt;span style="background: white; color: black"&gt;; }
}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Now SpellChecker can be imported by any importer with the same contract name as long as the importer is either a SpellChecker or a derived type.&lt;/p&gt;&lt;span style="background: white; color: black"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;h2&gt;Custom delegates&lt;/h2&gt;&lt;p&gt;In Preview 4, we only support Func and Action delegates for exports. Back by popular demand, we now support custom delegates again as we did in our earlier previews. This means that when you export a method, you can use a custom delegate, as opposed to having to use one of the pre-baked ones. For example in the code below, the Validate method is exporting ValidatorDelegate&amp;lt;Customer&amp;gt; which CustomerView is importing. String contracts are also fully supported. &lt;pre class="code"&gt;&lt;span style="background: white; color: blue"&gt;public delegate bool &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ValidatorDelegate&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;T&amp;gt;(T value);

&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;CustomerValidator
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
  [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;typeof&lt;/span&gt;&lt;span style="background: white; color: black"&gt;(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ValidatorDelegate&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Customer&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;gt;))]
  &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public bool &lt;/span&gt;&lt;span style="background: white; color: black"&gt;Validate(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Customer &lt;/span&gt;&lt;span style="background: white; color: black"&gt;customer)
  {
    &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;return &lt;/span&gt;&lt;span style="background: white; color: black"&gt;customer.Name != &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;null &lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;amp;&amp;amp; customer.Name != &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;String&lt;/span&gt;&lt;span style="background: white; color: black"&gt;.Empty;
  }
}&lt;/span&gt;&lt;/pre&gt;&lt;pre class="code"&gt;&lt;span style="background: white; color: black"&gt;[&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Export&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
&lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;CustomerView
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;  [&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ImportingConstructor&lt;/span&gt;&lt;span style="background: white; color: black"&gt;]
  &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public &lt;/span&gt;&lt;span style="background: white; color: black"&gt;CustomerView(&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;ValidatorDelegate&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Customer&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&amp;gt; validator)
  {
  }
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;}
&lt;/pre&gt;&lt;h2&gt;Directory Catalog changes&lt;/h2&gt;&lt;p&gt;Prior versions of the DirectoryCatalog internally used a FileSystemWatcher in order to notify the catalog that changes have occurred within the watched directory. Using the watcher was problematic for many reasons usually related to MEF trying to grab the file too early. Today it is very common for apps that enable the watcher to fail whenever a file is dropped in the folder. &lt;p&gt;As such we removed the watching functionality and replaced it with an explicit Refresh() method. The advantage of the refresh is it allows the host to determine when the refresh should occur. For example, a .NET Reflector type app could have a refresh button on the addins screen, the rescans the folders on demand. Once the folder is scanned, the catalog will do the delta to determine any changes, and it will fire change notifications as it does today, thus triggering re-composition in the container.&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="background: white; color: black"&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;pre class="code"&gt;&lt;span style="background: white; color: blue"&gt;public class &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;Application
&lt;/span&gt;&lt;span style="background: white; color: black"&gt;{
  &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;private &lt;/span&gt;&lt;span style="background: white; color: #2b91af"&gt;DirectoryCatalog &lt;/span&gt;&lt;span style="background: white; color: black"&gt;catalog;

  &lt;/span&gt;&lt;span style="background: white; color: green"&gt;//triggered by the user clicking the Refresh button on the addins page
  &lt;/span&gt;&lt;span style="background: white; color: blue"&gt;public void &lt;/span&gt;&lt;span style="background: white; color: black"&gt;Refresh()
  {
    catalog.Refresh();
  }
}&lt;/span&gt;&lt;/pre&gt;&lt;h2&gt;&lt;a name="_Toc226739126"&gt;Removal of caching / new infrastructure&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;We found several issues with our previous caching design which was black box. We’ve completely removed the old caching apis. We’ve added in a new API that can be used for caching, however we are not including a default caching implementation within MEF itself. We will however be shipping a caching API sample which illustrates how to use the APIs. The new APIs provides the further benefit of making it much easier to build new programming models that utilize reflection for are reflection based. &lt;p&gt;We’ve now introduced a new set of classes in System.ComponentModel.Composition.ReflectionModel that can be used by cache implementers. ReflectionModelServices provides a set of static helper methods that can be used for manufacturing part definitions from a cache store.&lt;/p&gt;&lt;span style="background: white; color: black"&gt;&lt;h2&gt;Summary&lt;/h2&gt;&lt;p&gt;A lot of new things to play with in preview 5. My personal favorite is the support we’ve now added for exports on interfaces, though I am sure if you ask different members of the team you’ll get a different answer.&amp;nbsp; &lt;/p&gt;&lt;p&gt;Thanks as always to the team for all their efforts, and thank you for your continual patience and feedback. We’re getting closer and closer to RTM!&lt;/p&gt;&lt;p&gt;So what are you waiting for? Go download MEF Preview 5 &lt;a href="http://mef.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=25797"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9546205" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q_jMNj4V51o:XLMnEGKCjvU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q_jMNj4V51o:XLMnEGKCjvU:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=Q_jMNj4V51o:XLMnEGKCjvU:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q_jMNj4V51o:XLMnEGKCjvU:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q_jMNj4V51o:XLMnEGKCjvU:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Q_jMNj4V51o:XLMnEGKCjvU:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=Q_jMNj4V51o:XLMnEGKCjvU:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/04/12/mef-preview-5-changes-and-enhancements.aspx</feedburner:origLink></item><item><title>Creating a functional programming model for MEF</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/Wgk1PahqD4k/creating-a-functional-programming-model-for-mef.aspx</link><pubDate>Fri, 03 Apr 2009 13:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9530483</guid><dc:creator>Glenn Block</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9530483.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9530483</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9530483</wfw:comment><description>&lt;P&gt;&lt;STRONG&gt;Disclaimer:&lt;/STRONG&gt; This is a prototype, not production ready code. It is more illustrative of what you can do with MEF, and how things work under the covers.&lt;/P&gt;
&lt;P&gt;The other day I was working one of our internal partners who is looking to integrate MEF into their framework stack. One of the interesting ideas that came out of that discussion was around a need they had to add POCO instances directly to a catalog (in addition to using our standard attributed part). &lt;/P&gt;
&lt;P&gt;Now MEF supports the ability to add existing instances to the container through the AddExportedObject method, but that did not suit their need.&amp;nbsp; Instead they wanted these instances to actually be parts. Primarily because the types they were instantiating were not attributed MEF parts, and they did not want to incur the reflection cost.&lt;/P&gt;
&lt;P&gt;I started thinking down the path of creating a programming model where the part definitions are actually wrapping instances. What I mean by programming model, is teach MEF a new way to represent parts, exports and imports. In MEF parlance, a programming model is almost like a type system, though far less complex. For more on programming models themselves, i'd refer you to Daniel's nice post on programming models themselves &lt;A href="http://blogs.msdn.com/dsplaisted/archive/2009/06/08/a-crash-course-on-the-mef-primitives.aspx" mce_href="http://blogs.msdn.com/dsplaisted/archive/2009/06/08/a-crash-course-on-the-mef-primitives.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Out of the box, MEF ships with an attributed programming model, however others can be created by implementing on top of a set of abstractions we call the primitives. What’s really nice about MEF is that all of the models can safely interact with one another in the container. &lt;/P&gt;
&lt;P&gt;Building an instance model however is problematic in that parts in MEF should be lazily instantiated. I realized (probably due much influence of my &lt;A href="http://code.google.com/p/autofac/" mce_href="http://code.google.com/p/autofac/"&gt;Autofac&lt;/A&gt; workmate &lt;A href="http://blogs.msdn.com/nblumhardt" mce_href="http://blogs.msdn.com/nblumhardt"&gt;Nick Blumhardt&lt;/A&gt;) that the right way to go was not build an instance model, but rather build a model for representing functions as parts. And so, the FuncCatalog was born. &lt;/P&gt;
&lt;H1&gt;FuncCatalog&lt;/H1&gt;
&lt;P&gt;The FuncCatalog allows you to add functions directly to itself, and to associate those functions with a type to be exported. Each function gets a single parameter which is an ExportProvider. This allows you to build up an instance within your function, that can have constructor parameters pulled from the EP, similar to the registration style in Autofac.&lt;/P&gt;
&lt;P&gt;Below is a sample acceptance test that illustrates how this works. In the example I am adding a function to funcCatalog which creates an OrderService. In the OrderService’s constructor, I am passing in an ILogger that I retrieved from the Export Provider.&lt;/P&gt;
&lt;P&gt;[&lt;SPAN style="COLOR: #2b91af"&gt;TestMethod&lt;/SPAN&gt;] &lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;public void &lt;/SPAN&gt;FuncPartCanImportFromTheContainer() &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;catalog = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AggregateCatalog&lt;/SPAN&gt;(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; catalog.Catalogs.Add(&lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;TypeCatalog&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;typeof &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;AttributedLogger&lt;/SPAN&gt;)));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;funcCatalog = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncCatalog&lt;/SPAN&gt;(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; funcCatalog.AddPart&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;OrderService&lt;/SPAN&gt;&amp;gt;( &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ep =&amp;gt; &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;OrderService&lt;/SPAN&gt;(ep.GetExportedObject&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ILogger&lt;/SPAN&gt;&amp;gt;())); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; catalog.Catalogs.Add(funcCatalog); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;container = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CompositionContainer&lt;/SPAN&gt;(catalog); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;batch = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CompositionBatch&lt;/SPAN&gt;(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; batch.AddExportedObject&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider&lt;/SPAN&gt;&amp;gt;(container); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; container.Compose(batch); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;service = container.GetExportedObject&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;OrderService&lt;/SPAN&gt;&amp;gt;(); &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;Assert&lt;/SPAN&gt;.IsNotNull(service.Logger); &lt;BR&gt;}&lt;/P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;In terms of what the code is doing, I am first creating an aggregate catalog (a catalog of catalogs). Then I am adding to it a type catalog which contains an AttributedLogger (that is a logger with an ExportAttribute on it). Next I am creating a FuncCatalog which I am adding the new func part to. Notice how the lambda passes ep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ep =&amp;gt; &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;OrderService&lt;/SPAN&gt;(ep.GetExportedObject&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ILogger&lt;/SPAN&gt;&amp;gt;())&lt;/P&gt;
&lt;P&gt;Next I am creating the container, and then adding itself to itself (via the batch) with ExportProvider as the contract. This is to allow the FuncPart to import the ExportProvider so it can use it to resolve other dependencies. &lt;/P&gt;
&lt;P&gt;Finally I am asking the container to grab me an OrderService, which I am then checking to see if there is a logger present. Remember the logger actually was an attributed part that was added through MEF’s normal catalogs. So right here we have an illustration of multiple models living side by side.&lt;/P&gt;
&lt;H1&gt;&lt;/H1&gt;
&lt;H1&gt;&lt;/H1&gt;
&lt;H1&gt;How is it done?&lt;/H1&gt;
&lt;P&gt;As I mentioned above, I created a custom programming model. Depending on the model, this can be a lot or a little work. &lt;A href="http://www.thecodejunkie.com/" mce_href="http://www.thecodejunkie.com/"&gt;Andreas Haakanson&lt;/A&gt; has a project on CodePlex that simplifies creating such programming models, but that is for another overdue post :-)&amp;nbsp; Below I’ll detail the approach I took in order to give you a view into how programming models work. &lt;/P&gt;
&lt;H1&gt;Programming model players&lt;/H1&gt;
&lt;P&gt;Below are the main abstractions you&amp;nbsp; need to implement for building your own programming model which live in the System.ComponentModel.Composition.Primitives namespace.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_4.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_thumb_1.png" width=532 height=293 mce_src="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_thumb_1.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Here’s&amp;nbsp; a quick summary of the responsibilities for each of these classes.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;ComposablePartDefinition&lt;/STRONG&gt; – Schema for a part, analogous to a type in many respects. As a matter of fact in our default Attributed Programming Model (APM), the Composable Part Definition wraps a type. Aside from being schema, the other main responsibility for CPD is to create a composable part. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ImportDefinition&lt;/STRONG&gt; – An import definition is carries information about a contract that a part needs, it’s import. In the APM, import definitions are created for properties decorated with the ImportAttribute, or constructor parameters if the constructor has an ImportingConstructorAttribute. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ExportDefinition&lt;/STRONG&gt; - An export definition carries information about a contract that a part offers up, it’s export. In the APM, an export definition is created for each member that is decorated with the ExportAttribute. This includes the class itself, or methods / properties. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ComposablePartCatalog&lt;/STRONG&gt; – The catalog aggregates part definitions, which the container will query during composition in order to find available exports. The catalog does not create any parts, it only returns requested definitions. In our APM, the catalogs read assemblies and types in order to create these definitions. &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;ComposablePart –&lt;/STRONG&gt; The part itself. If the CPD is the schema, then the part is the instance. This does not mean it is the actual instance that is being returned from the container. No. The part contains an instance which will get created only at the time when the first exported object actually pulled from it. There’s a difference between an export and an exported object, but I’ll resist to go deeper and try to explain it for now. &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In my new model I implemented FuncCatalog, FuncExportDefinition, FuncPart, and FuncPartDefinition. I did not need a new ImportDefinition as the standard one was fine. Also my parts only support a single import, namely an ExportProvider.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_8.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_thumb_3.png" width=538 height=310 mce_src="http://blogs.msdn.com/blogfiles/gblock/WindowsLiveWriter/CreatingafunctionalprogrammingmodelforME_B37/image_thumb_3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H1&gt;FuncExportDefinition&lt;/H1&gt;
&lt;P&gt;Ok, so first stop is to build a FuncExportDefinition. In my case I need a definition that carries a custom function. So here it is.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncExportDefinition &lt;/SPAN&gt;: &lt;SPAN style="COLOR: #2b91af"&gt;ExportDefinition
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;FuncExportDefinition(&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;contractName, 
        &lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider&lt;/SPAN&gt;,&lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt; factory) :
        &lt;SPAN style="COLOR: blue"&gt;base&lt;/SPAN&gt;(contractName, &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;)
    {
        Factory = factory;
    }

    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt; Factory { &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: blue"&gt;private set&lt;/SPAN&gt;; }
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Pretty simple, I basically allow associating a contract and an additional func which accepts an ExportProvider as a parameter and returns object. Now notice the second parameter I pass to the base class is null. That represents metadata. I decided for simplicity to not allow support of metadata, though that could easily be added back.&lt;/P&gt;
&lt;H1&gt;FuncPartDefinition&lt;/H1&gt;
&lt;P&gt;Now that I can define Funcs as exports, I need a PartDefinition which can carry that information, and manufacture a part. This one was a bit tricky, below are the important pieces.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;public abstract class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition &lt;/SPAN&gt;: &lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartDefinition
&lt;/SPAN&gt;{}

&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;&amp;lt;TContract&amp;gt; : &lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition 
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;private static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ContractBasedImportDefinition 
        &lt;/SPAN&gt;_exportProviderImportDefinition;


    &lt;SPAN style="COLOR: blue"&gt;static &lt;/SPAN&gt;FuncPartDefinition()
    {
        &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;importContractName = &lt;SPAN style="COLOR: #2b91af"&gt;CompositionServices&lt;/SPAN&gt;.GetContractName
            (&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider&lt;/SPAN&gt;));
        _exportProviderImportDefinition = &lt;SPAN style="COLOR: blue"&gt;new 
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ContractBasedImportDefinition&lt;/SPAN&gt;(
            importContractName, &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;,
            &lt;SPAN style="COLOR: #2b91af"&gt;ImportCardinality&lt;/SPAN&gt;.ZeroOrOne, &lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;,
            &lt;SPAN style="COLOR: #2b91af"&gt;CreationPolicy&lt;/SPAN&gt;.Any);
    }

    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;FuncPartDefinition(&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt; factory)
    {
        _exportDefinitions.Add(&lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncExportDefinition
            &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;CompositionServices&lt;/SPAN&gt;.GetContractName(&lt;SPAN style="COLOR: blue"&gt;typeof&lt;/SPAN&gt;(TContract)),
            factory));
        _importDefinitions.Add(_exportProviderImportDefinition);
    }

    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;FuncPartDefinition()
        : &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;((ep)=&amp;gt;(TContract) &lt;SPAN style="COLOR: #2b91af"&gt;Activator&lt;/SPAN&gt;.
            CreateInstance(&lt;SPAN style="COLOR: blue"&gt;typeof &lt;/SPAN&gt;(TContract)))
    {
    }

    &lt;SPAN style="COLOR: blue"&gt;public override &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ComposablePart &lt;/SPAN&gt;CreatePart()
    {
        &lt;SPAN style="COLOR: blue"&gt;return new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPart&lt;/SPAN&gt;&amp;lt;TContract&amp;gt;(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;);
    }
}&lt;/PRE&gt;
&lt;H1&gt;&lt;/H1&gt;
&lt;P&gt;As I mentioned earlier, my func parts need to access an ExportProvider so they can retrieve things from the container. The question was how to do this. I could make the ExportProvider a parameter on the constructor of the part. Then however, I would have to pass it in to the catalog, which would pass it in to the part. This is further problematic as catalogs can actually be passed to several containers. So I decided the easiest way to do it, was to have the part actually import the ExportProvider through MEF’s composition, that is similar to the way I would import on an attributed part through a constructor param. &lt;/P&gt;
&lt;P&gt;In order to do this, all I need is to add a single ImportDefinition to every part instance. The static constructor of FuncPartDefinition does the work of creating this definition. The definition never changes, and it is cheaper to create it once, which is&amp;nbsp; why I made it static.&lt;/P&gt;
&lt;P&gt;The instance constructor accepts the&amp;nbsp; func. It then goes and creates a FuncExportDefinition which it adds to the collection of export definitions. Next it adds the export provider import. I added an additional overload just as a convenience which simply creates the type. Probably just being gratuitous ;-)&lt;/P&gt;
&lt;P&gt;Finally the CreatePart method goes and creates a FuncPart passing in the definition (the part’s schema) which leads us to our next suspect.&lt;/P&gt;
&lt;H1&gt;FuncPart&lt;/H1&gt;
&lt;P&gt;This guys job is to pass back export definitions of our func, to the container on request. Those definitions can later be activated to invoke the actual func.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPart&lt;/SPAN&gt;&amp;lt;TContract&amp;gt; : &lt;SPAN style="COLOR: #2b91af"&gt;ComposablePart 
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;private &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;&amp;lt;TContract&amp;gt; _definition;
    &lt;SPAN style="COLOR: blue"&gt;private &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider &lt;/SPAN&gt;_provider;

    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;FuncPart(&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;&amp;lt;TContract&amp;gt; definition)
    {
        _definition = definition;
    }

    &lt;SPAN style="COLOR: blue"&gt;public override object &lt;/SPAN&gt;GetExportedObject(&lt;SPAN style="COLOR: #2b91af"&gt;ExportDefinition &lt;/SPAN&gt;definition)
    {
        &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;funcExportDefinition = definition &lt;SPAN style="COLOR: blue"&gt;as &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncExportDefinition&lt;/SPAN&gt;;
        &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;funcExportDefinition.Factory(_provider);
    }

    &lt;SPAN style="COLOR: blue"&gt;public override void &lt;/SPAN&gt;SetImport(&lt;SPAN style="COLOR: #2b91af"&gt;ImportDefinition &lt;/SPAN&gt;definition, 
        &lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Export&lt;/SPAN&gt;&amp;gt; exports)
    {
        _provider = exports.First().GetExportedObject() &lt;SPAN style="COLOR: blue"&gt;as &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider&lt;/SPAN&gt;;
    }

    &lt;SPAN style="COLOR: blue"&gt;public override &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportDefinition&lt;/SPAN&gt;&amp;gt; ExportDefinitions
    {
        &lt;SPAN style="COLOR: blue"&gt;get &lt;/SPAN&gt;{ &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;_definition.ExportDefinitions; }
    }

    &lt;SPAN style="COLOR: blue"&gt;public override &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ImportDefinition&lt;/SPAN&gt;&amp;gt; ImportDefinitions
    {
        &lt;SPAN style="COLOR: blue"&gt;get &lt;/SPAN&gt;{ &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;_definition.ImportDefinitions; }
    }
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;When the part gets constructed, it stores a copy of it’s definition. The ExportDefinitions and ImportDefinitions delegate directly to the part definitions members. In the SetImport method I have got a bit of a hack going on. This method will get called by the composition engine to set the imports. In the method, I am grabbing the first export passed in and then assuming it is the export provider. This is actually an OK assumption in my case, since there is only a single import that I allow in my programming model. However, I really should be verifying that it is passing me the right definition.&lt;/P&gt;
&lt;P&gt;And just when you thought I was done with hacks, another one :-) GetExportedObject takes the definition passed to it and assumes it is a FuncExportDefinition. Again, this is an ok assumption in the cases where I am using it, but it should be more bullet proof and not make those assumptions. Anyway, once it has the definition&amp;nbsp; unwrapped, it grabs the factory and invokes it passing in the provider.&lt;/P&gt;
&lt;H1&gt;FuncCatalog&lt;/H1&gt;
&lt;P&gt;Last stop on our journey is the func catalog.&amp;nbsp; He’s actually pretty straightforward. I added a few convenience methods on him so that you don’t have to create parts a head of time.&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;public class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncCatalog &lt;/SPAN&gt;: &lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartCatalog&lt;/SPAN&gt;,     
    &lt;SPAN style="COLOR: #2b91af"&gt;INotifyComposablePartCatalogChanged
&lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;private &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartDefinition&lt;/SPAN&gt;&amp;gt; _parts = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartDefinition&lt;/SPAN&gt;&amp;gt;();

    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition &lt;/SPAN&gt;AddPart&amp;lt;T&amp;gt;(
        &lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ExportProvider&lt;/SPAN&gt;, &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt; factory)
    {
        &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;addedParts = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;List&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;&amp;gt;();
        &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;definition = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;&amp;lt;T&amp;gt;(factory);
        _parts.Add(definition);
        
        addedParts.Add(definition);
        OnChanged(addedParts);
        &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;definition;

    }

    &lt;SPAN style="COLOR: blue"&gt;public void &lt;/SPAN&gt;AddParts(&lt;SPAN style="COLOR: blue"&gt;params &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;[] parts)
    {
        _parts.AddRange(parts);
        OnChanged(parts);
    }

    &lt;SPAN style="COLOR: blue"&gt;public void &lt;/SPAN&gt;RemoveParts(&lt;SPAN style="COLOR: blue"&gt;params &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;[] parts)
    {
        _parts.RemoveAll(c =&amp;gt; parts.Contains(c));
        OnChanged(parts);
    }
    
    &lt;SPAN style="COLOR: blue"&gt;public override &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IQueryable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartDefinition&lt;/SPAN&gt;&amp;gt; Parts
    {
        &lt;SPAN style="COLOR: blue"&gt;get
        &lt;/SPAN&gt;{
            &lt;SPAN style="COLOR: blue"&gt;return &lt;/SPAN&gt;_parts.AsQueryable();
        }
    }

    &lt;SPAN style="COLOR: blue"&gt;private void &lt;/SPAN&gt;OnChanged(&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;FuncPartDefinition&lt;/SPAN&gt;&amp;gt; parts)
    {
        &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;args = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartCatalogChangedEventArgs&lt;/SPAN&gt;(
            parts.Cast&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartDefinition&lt;/SPAN&gt;&amp;gt;());
        Changed(&lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;, args);
    }

    &lt;SPAN style="COLOR: blue"&gt;public event &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;EventHandler&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;ComposablePartCatalogChangedEventArgs&lt;/SPAN&gt;&amp;gt; 
        Changed = &lt;SPAN style="COLOR: blue"&gt;delegate &lt;/SPAN&gt;{ };
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;First thing is the catalog implements INotifyComposablePartCatalogChanged. This is to allow the catalog to notify the container when parts are added or removed from it. Implementing a catalog only requires to to override one property, namely the Parts property, which as you can see returns a queryable of Parts. The rest of the methods are concerned with the mutability of the container. Now catalogs do not have to be mutable, as you can handle loading up all the part defs in the constructor. However, for usability sake, I wanted mine to&amp;nbsp; be mutable. This means that I need to have methods for adding, removing, and I need to support notification.&amp;nbsp; The code should be pretty easy to follow.&lt;/P&gt;
&lt;H1&gt;&lt;/H1&gt;
&lt;H1&gt;So what have we learned?&lt;/H1&gt;
&lt;P&gt;Well first thing we learned that MEF supports alternative programming models other than the attributed model we ship in the box. Next, we learned about the key concepts involved in authoring your own programming model. In this case the model was very, very simple, which is why I was able to cover it in a single post. I am not recommending every one go out an author their own model. Lastly we saw learned that parts can be functions :-)&lt;/P&gt;
&lt;P&gt;If your interested in other applications of programming models in MEF, I recommend you check out Nick Blumhart’s posts on Ruby. Also don’t forget to check out &lt;A href="http://www.thecodejunkie.com/" mce_href="http://www.thecodejunkie.com"&gt;Andreas’s&lt;/A&gt; &lt;A href="http://mefcontrib.codeplex.com/Wiki/View.aspx?title=Documentation%20%26%20Features&amp;amp;referringTitle=Home" mce_href="http://mefcontrib.codeplex.com/Wiki/View.aspx?title=Documentation%20%26%20Features&amp;amp;referringTitle=Home"&gt;provider based programming model&lt;/A&gt; on MefContrib. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9530483" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Wgk1PahqD4k:mO27VuRkhJM:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Wgk1PahqD4k:mO27VuRkhJM:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=Wgk1PahqD4k:mO27VuRkhJM:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Wgk1PahqD4k:mO27VuRkhJM:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Wgk1PahqD4k:mO27VuRkhJM:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=Wgk1PahqD4k:mO27VuRkhJM:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=Wgk1PahqD4k:mO27VuRkhJM:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><enclosure url="http://cid-f8b2fd72406fb218.skydrive.live.com/self.aspx/blog/FuncCatalogExtensions.zip" length="37590" type="text/html; charset=utf-8" /><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/04/03/creating-a-functional-programming-model-for-mef.aspx</feedburner:origLink></item><item><title>Why doesn’t MEF support open-generics for exports? Because MEF is not type based.</title><link>http://feedproxy.google.com/~r/MyTechnobabble/~3/UkH8f0cs7Cw/why-doesn-t-mef-support-open-generics-for-exports-because-mef-is-not-type-based.aspx</link><pubDate>Sat, 21 Mar 2009 23:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9496386</guid><dc:creator>Glenn Block</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/gblock/comments/9496386.aspx</comments><wfw:commentRss>http://blogs.msdn.com/gblock/commentrss.aspx?PostID=9496386</wfw:commentRss><wfw:comment>http://blogs.msdn.com/gblock/rsscomments.aspx?PostID=9496386</wfw:comment><description>&lt;P&gt;&lt;STRONG&gt;Update: We've posted an extension for doing open generics in MEF contrib. Read about it here: &lt;A href="http://blogs.msdn.com/gblock/archive/2009/08/20/open-generic-support-in-mef-contrib.aspx"&gt;http://blogs.msdn.com/gblock/archive/2009/08/20/open-generic-support-in-mef-contrib.aspx&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;I get this question all the time. Recently it popped it’s head on the forums in this &lt;A href="http://mef.codeplex.com/Thread/View.aspx?ThreadId=50504" mce_href="http://mef.codeplex.com/Thread/View.aspx?ThreadId=50504"&gt;thread&lt;/A&gt; (which I referred to in my last &lt;A href="http://codebetter.com/blogs/glenn.block/archive/2009/03/21/recomposition-and-constructors.aspx" mce_href="http://codebetter.com/blogs/glenn.block/archive/2009/03/21/recomposition-and-constructors.aspx"&gt;post&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;In that thread, Andrew was asking why the following does not work?&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[Export(&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;(IDomainController&amp;lt;&amp;gt;)), CompositionOptions(CreationPolicy = CreationPolicy.Shared)]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; DomainController&amp;lt;T&amp;gt; : IDomainController&amp;lt;T&amp;gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;{&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #008000"&gt;/* some code here */&lt;/SPAN&gt;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  [ImportingConstructor]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; DomainController(IRepository repository)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  {&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;    _Repository = repository&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  }&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;} &lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;That is he wants to export a generic IDomainController with the idea the closed generic versions like IDomainController&amp;lt;Customer&amp;gt; could be imported.&lt;/P&gt;
&lt;P&gt;He also rightly observed that many of the IoC containers that exist support this functionality including &lt;A href="http://msdn.microsoft.com/unity" mce_href="http://msdn.microsoft.com/unity"&gt;Unity&lt;/A&gt;. (I chuckled when I heard that because I was in p&amp;amp;p when we first wrote Unity) However, it is a valid question, why don’t we support it? This is one of those questions that I, &lt;A href="http://hammett.castleproject.org/" mce_href="http://hammett.castleproject.org/"&gt;Hammett&lt;/A&gt; and &lt;A href="http://blogs.msdn.com/nblumhardt" mce_href="http://blogs.msdn.com/nblumhardt"&gt;Nick&lt;/A&gt; all asked when we joined the team.&amp;nbsp; We do support closed generics without a problem, but not open. Why?&lt;/P&gt;
&lt;P&gt;As you dig into the details, it quickly becomes clear. The root of the answer is that MEF is not type based, it is contract based. Below are the details from my response…&lt;/P&gt;
&lt;P&gt;MEF parts relate on contracts which are strings, not types. To illustrate, see the code below.&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Orders {&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;interface&lt;/SPAN&gt; IOrderRepository {}&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  [Export(&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;(IOrderRespository))]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; OrderRepository : IOrderRepository {&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  }&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;}&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;Although I have passed typeof(IOrderRepository) to the export, that is just a convenience that gets converted to a contract name of "Orders.IOrderRepository". The same applies to the importer...&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[Export]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; OrderService(&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  [Import]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IOrderRepository Repository {gets;set;} &lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P align=left&gt;The import on IOrderRepository also gets converted to a contract name of "Orders.IOrderRepository". During composition, the container is able to satisfy the import as the 2 contracts match. In the same way we support closed generics, so this code....&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;interface&lt;/SPAN&gt; IRepository&amp;lt;T&amp;gt; {}&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[Export(&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;(IRepository&amp;lt;Order&amp;gt;))]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; OrderRepository : IRepository&amp;lt;Order&amp;gt; {&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;}&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[Export]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; OrderService(&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  [Import]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IRepository&amp;lt;Order&amp;gt; Repository {gets;set;} &lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P align=left&gt;will work because the OrderRepository is exporting the contract name "Orders.IRepository&amp;lt;Order&amp;gt;" and the OrderService is importing the same contract.&lt;/P&gt;
&lt;P align=left&gt;However, this is what it looks like if we try the same with open generics.&lt;/P&gt;
&lt;DIV id=codeSnippetWrapper&gt;
&lt;DIV style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px" id=codeSnippet&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;interface&lt;/SPAN&gt; IRepository&amp;lt;T&amp;gt; {}&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;namespace&lt;/SPAN&gt; Utils {&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  [Export(&lt;SPAN style="COLOR: #0000ff"&gt;typeof&lt;/SPAN&gt;(IRepository&amp;lt;&amp;gt;))]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; Repository : IRepository&amp;lt;T&amp;gt; {&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  }&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;}&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;[Export]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; OrderService(&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  [Import]&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;  &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; IRepository&amp;lt;Order&amp;gt; Repository {gets;set;} &lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;PRE style="BORDER-BOTTOM-STYLE: none; TEXT-ALIGN: left; PADDING-BOTTOM: 0px; LINE-HEIGHT: 12pt; BORDER-RIGHT-STYLE: none; BACKGROUND-COLOR: white; MARGIN: 0em; PADDING-LEFT: 0px; WIDTH: 100%; PADDING-RIGHT: 0px; FONT-FAMILY: 'Courier New', courier, monospace; DIRECTION: ltr; BORDER-TOP-STYLE: none; COLOR: black; FONT-SIZE: 8pt; BORDER-LEFT-STYLE: none; OVERFLOW: visible; PADDING-TOP: 0px"&gt;)&lt;/PRE&gt;&lt;!--CRLF--&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P align=left&gt;Now the contract names will be different. The exporter will have a contract of&amp;nbsp; "Utils.IRepository&amp;lt;&amp;gt;" and the importer will have a contract of "Utils.IRepository&amp;lt;Order&amp;gt;". &lt;BR&gt;&lt;/P&gt;
&lt;P align=left&gt;It is a simple match up, that breaks down in the open-generics case. This is because fundamentally, MEF is not matching on type. &lt;/P&gt;
&lt;P&gt;There are theoretical ways to address it, but they are all very ugly, require a lot of string parsing and really go against the grain of MEF’s core design.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9496386" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=UkH8f0cs7Cw:1mxmb55tscc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=UkH8f0cs7Cw:1mxmb55tscc:V_sGLiPBpWU"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=UkH8f0cs7Cw:1mxmb55tscc:V_sGLiPBpWU" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=UkH8f0cs7Cw:1mxmb55tscc:qj6IDK7rITs"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=qj6IDK7rITs" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=UkH8f0cs7Cw:1mxmb55tscc:I9og5sOYxJI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?d=I9og5sOYxJI" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/MyTechnobabble?a=UkH8f0cs7Cw:1mxmb55tscc:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/MyTechnobabble?i=UkH8f0cs7Cw:1mxmb55tscc:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://blogs.msdn.com/gblock/archive/tags/MEF/default.aspx">MEF</category><category domain="http://blogs.msdn.com/gblock/archive/tags/generics/default.aspx">generics</category><feedburner:origLink>http://blogs.msdn.com/gblock/archive/2009/03/21/why-doesn-t-mef-support-open-generics-for-exports-because-mef-is-not-type-based.aspx</feedburner:origLink></item></channel></rss>
