<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" 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/"><channel><title>MEF: Dependencies are Queries?</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx</link><description>Start to schematically represent any component system and you’re likely to come up with a diagram like: So what do the dependency and the service actually mean ? In most implementations, each is associated with a key: Here the Screen Renderer component</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: MEF: Dependencies are Queries?</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx#9806627</link><pubDate>Sat, 27 Jun 2009 17:54:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806627</guid><dc:creator>David Barrett</dc:creator><description>&lt;p&gt;Gotcha. &amp;nbsp;So I wan't being an idiot when I couldn't find the attribute overload to provide this out of the box? &amp;nbsp;:)&lt;/p&gt;
&lt;p&gt;Thanks so much for the reply, Nick. &amp;nbsp;I'll just use IQueryable to get the items I want/need. &amp;nbsp;I look forward to seeing how MEF matures and develops. &amp;nbsp;Neat stuff so far!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9806627" width="1" height="1"&gt;</description></item><item><title>re: MEF: Dependencies are Queries?</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx#9806125</link><pubDate>Sat, 27 Jun 2009 03:06:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806125</guid><dc:creator>niblumha</dc:creator><description>&lt;p&gt;Hi David,&lt;/p&gt;
&lt;p&gt;The architecture supports it - you can construct an instance of ImportDefinition with any arbitrary constraint you require (there are some perf caveats to this.)&lt;/p&gt;
&lt;p&gt;There is, however, no high-level support in the attributed programming model (e.g. via the [Import] attribute) so in your case the best option is to use:&lt;/p&gt;
&lt;p&gt;[ImportMany]&lt;/p&gt;
&lt;p&gt;Export&amp;lt;IFoo, IFooMetadata&amp;gt;[] services;&lt;/p&gt;
&lt;p&gt;...and then select from the services as required:&lt;/p&gt;
&lt;p&gt;var servicesForX = services.Where(svc =&amp;gt; svc.MetadataView.Purpose == &amp;quot;X&amp;quot;);&lt;/p&gt;
&lt;p&gt;Lazy instantiation means that you'll only instantiate the service instance you actually use.&lt;/p&gt;
&lt;p&gt;In the future we hope to simplify this scenario. You can consider this post a peek under the hood and a nod to the kinds of things we may build in the future.&lt;/p&gt;
&lt;p&gt;Hope this helps!&lt;/p&gt;
&lt;p&gt;Nick&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9806125" width="1" height="1"&gt;</description></item><item><title>re: MEF: Dependencies are Queries?</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx#9806088</link><pubDate>Sat, 27 Jun 2009 02:30:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9806088</guid><dc:creator>David Barrett</dc:creator><description>&lt;p&gt;Does this work today in MEF Preview 5? &amp;nbsp;I mean, is it possible to provide this sort of constraint? &amp;nbsp;I'm trying desperately to filter a list of exports that satisfy an import based on a piece of metadata but can't seem to get it to work.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9806088" width="1" height="1"&gt;</description></item><item><title>A Crash Course on the MEF Primitives</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx#9712912</link><pubDate>Tue, 09 Jun 2009 08:53:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9712912</guid><dc:creator>Daniel Plaisted's Blog</dc:creator><description>&lt;p&gt;With the Managed Extensibility Framework (MEF), you can use Import and Export attributes to declare what&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9712912" width="1" height="1"&gt;</description></item><item><title>re: MEF: Dependencies are Queries?</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx#9553518</link><pubDate>Fri, 17 Apr 2009 00:34:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9553518</guid><dc:creator>niblumha</dc:creator><description>&lt;p&gt;Hi Bill!&lt;/p&gt;
&lt;p&gt;I'm not sure there is any more coupling - just a tighter contract.&lt;/p&gt;
&lt;p&gt;Examples that fit on a page are hard to come by...&lt;/p&gt;
&lt;p&gt;Compilers in an IDE may be another illustrative example. ICompiler is annotated with metadata describing the language that can be compiled. A build tool will want a compiler for a specific language, while a configuration tool may wish to list all of the available compilers.&lt;/p&gt;
&lt;p&gt;This is one of a set of scenarios that the techniques you described are harder to adapt to - using contracts with metadata is more flexible than creating interfaces for every specialisation, or methods for every combination of capabilities.&lt;/p&gt;
&lt;p&gt;Hope this illustrates the difference a little better - please keep the questions coming.&lt;/p&gt;
&lt;p&gt;Nick&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9553518" width="1" height="1"&gt;</description></item><item><title>re: MEF: Dependencies are Queries?</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx#9553361</link><pubDate>Thu, 16 Apr 2009 22:00:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9553361</guid><dc:creator>Bill Pierce</dc:creator><description>&lt;p&gt;Doesn't this make service consumers more tightly coupled with service providers? &amp;nbsp;If I need a fast typesetter why wouldn't I resolve an IFastTypeSetter? &amp;nbsp;Or add RenderFast and RenderAccurate methods to ITypeSetter?&lt;/p&gt;
&lt;p&gt;I think more concrete examples would aid the discussion.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9553361" width="1" height="1"&gt;</description></item><item><title>MEF: Dependencies are Queries? - Nicholas Blumhardt</title><link>http://blogs.msdn.com/b/nblumhardt/archive/2009/04/16/mef-dependencies-are-queries.aspx#9551821</link><pubDate>Thu, 16 Apr 2009 03:04:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9551821</guid><dc:creator>DotNetShoutout</dc:creator><description>&lt;p&gt;Thank you for submitting this cool story - Trackback from DotNetShoutout&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9551821" width="1" height="1"&gt;</description></item></channel></rss>