<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://eduncan911.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>Managed Extensibility Framework (MEF) - Microsoft's Official Inversion of Control Container</title><link>http://eduncan911.com/blog/managed-extensibility-framework-mef-microsofts-official-inversion-of-control-container.aspx</link><description>This new Microsoft feature in .NET Framework 4 is a programming model for reusing components, very similar to those Inversion of Control container frameworks out there that we all know and love (Castle Windsor, Structured Map, their own Unity from the</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Managed Extensibility Framework (MEF) - Microsoft's Official Inversion of Control Container</title><link>http://eduncan911.com/blog/managed-extensibility-framework-mef-microsofts-official-inversion-of-control-container.aspx#6965</link><pubDate>Tue, 16 Feb 2010 11:05:57 GMT</pubDate><guid isPermaLink="false">3cbf8099-f611-4197-a0f5-c5a9f8954971:6965</guid><dc:creator>Glenn Block</dc:creator><description>&lt;p&gt;Nice post Eric. I like the way you broke down the benefits MEF brings to the table. I do have a bit of an issue with the &amp;quot;MEF is the MS IoC container&amp;quot; angle :-) It is not to say that MEF does not support IoC, it does, but it's about how it supports it and the design goals. Both of which should be evaluated before simply jumping off your current IoC mechanism.&lt;/p&gt;
&lt;p&gt;I posted a while ago on how MEF compares to a conventional IoC. It is worth a read for anyone reading this post: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/gblock/archive/2009/08/16/should-i-use-mef-for-my-general-ioc-needs.aspx"&gt;http://blogs.msdn.com/gblock/archive/2009/08/16/should-i-use-mef-for-my-general-ioc-needs.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Aside from that, I do have few questions / observations on the post. &lt;/p&gt;
&lt;p&gt;One the lazy example, doesn't appear to be lazy. Also it is not showing anything that other container's don't already support. MEF does allow imports to be Lazy&amp;lt;T&amp;gt; or Lazy&amp;lt;T,M&amp;gt; which delays instantiation of components.&lt;/p&gt;
&lt;p&gt;Second question is wrt to the App Startup code. I am having a hard time seeing how that code as is is particularly useful. Are you expecting the app startup has imports on it? Being brutally honest, there are a bunch of challenges around using MEF on the web, and I think this is oversimplifying it. To really be useful you need to create hiearchical containers in order to manage request-level scoping of components and such. I am not saying the approach of a simple app-level container has no usefulness, but it is limited.&lt;/p&gt;
&lt;p&gt;Hammett addresses a lot of these concerns in the code for his post here: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx"&gt;http://blogs.msdn.com/hammett/archive/2009/04/23/mef-and-asp-net-mvc-sample.aspx&lt;/a&gt;. We are looking into more rudimentry support for ASP.NET scenarios going forward.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Glenn&lt;/p&gt;
</description></item><item><title>re: Managed Extensibility Framework (MEF) - Microsoft's Official Inversion of Control Container</title><link>http://eduncan911.com/blog/managed-extensibility-framework-mef-microsofts-official-inversion-of-control-container.aspx#6966</link><pubDate>Tue, 16 Feb 2010 11:33:02 GMT</pubDate><guid isPermaLink="false">3cbf8099-f611-4197-a0f5-c5a9f8954971:6966</guid><dc:creator>Glenn Block</dc:creator><description>&lt;p&gt;Thanks for the nice comments on the article. Glad that found it useful and that you are finding MEF intuitive and easy to use.&lt;/p&gt;
&lt;p&gt;Looking forward to seeing more posts in the future!&lt;/p&gt;
&lt;p&gt;Glenn&lt;/p&gt;
</description></item><item><title>re: Managed Extensibility Framework (MEF) - Microsoft's Official Inversion of Control Container</title><link>http://eduncan911.com/blog/managed-extensibility-framework-mef-microsofts-official-inversion-of-control-container.aspx#6967</link><pubDate>Tue, 16 Feb 2010 16:23:46 GMT</pubDate><guid isPermaLink="false">3cbf8099-f611-4197-a0f5-c5a9f8954971:6967</guid><dc:creator>Eric A. Duncan</dc:creator><description>&lt;p&gt;@Glenn: &lt;/p&gt;
&lt;p&gt;Thanks for the reply!&lt;/p&gt;
&lt;p&gt;Ah, excellent catch about the lazy loading. &amp;nbsp;After I re-read your article, I see now that MEF would immediately wire that up - so it isn't really lazy loading in the sense of UserService is immediately available. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Yep, the Lazy&amp;lt;T&amp;gt; sounds about right for what I would need to implement there. &amp;nbsp;I will make corrections shortly on that - and actually write some code for it (everything above is pseudo code). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which, explains the global.asax code above. &amp;nbsp;I was following your example in the article. &amp;nbsp;I will look into the mvc and mef article you posted, as this interests me greatly.&lt;/p&gt;
&lt;p&gt;This was exactly what I was looking for. &amp;nbsp;Thanks man!&lt;/p&gt;
</description></item><item><title>re: Managed Extensibility Framework (MEF) - Microsoft's Official Inversion of Control Container</title><link>http://eduncan911.com/blog/managed-extensibility-framework-mef-microsofts-official-inversion-of-control-container.aspx#6968</link><pubDate>Wed, 17 Feb 2010 17:23:45 GMT</pubDate><guid isPermaLink="false">3cbf8099-f611-4197-a0f5-c5a9f8954971:6968</guid><dc:creator>Glenn Block</dc:creator><description>&lt;p&gt;No problem Eric. The sample in my article was around using the Application class in WPF/SL. These are different because they are stateful and correspond to a single &amp;quot;session&amp;quot; / instance. In the web things are much more complex as the Application is global and shared across many many requests. Those requests are transient rather than stateful.&lt;/p&gt;
&lt;p&gt;I hint at some of the intracacies in the bottom of this post: &lt;a rel="nofollow" target="_new" href="http://codebetter.com/blogs/glenn.block/archive/2010/01/15/hosting-mef-within-your-applications.aspx"&gt;http://codebetter.com/blogs/glenn.block/archive/2010/01/15/hosting-mef-within-your-applications.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Glad to help.&lt;/p&gt;
</description></item><item><title>re: Managed Extensibility Framework (MEF) - Microsoft's Official Inversion of Control Container</title><link>http://eduncan911.com/blog/managed-extensibility-framework-mef-microsofts-official-inversion-of-control-container.aspx#6969</link><pubDate>Wed, 17 Feb 2010 17:32:06 GMT</pubDate><guid isPermaLink="false">3cbf8099-f611-4197-a0f5-c5a9f8954971:6969</guid><dc:creator>Glenn Block</dc:creator><description>&lt;p&gt;Forgot to mention, I like the part that you added on the property exports being used for Factories. I touch on the power of property exports here: &lt;a rel="nofollow" target="_new" href="http://codebetter.com/blogs/glenn.block/archive/2010/01/27/how-do-i-expose-configuration-information-through-mef.aspx"&gt;http://codebetter.com/blogs/glenn.block/archive/2010/01/27/how-do-i-expose-configuration-information-through-mef.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;One thing on the factory though, depending on the desired behavior you may want to set the creation policy to non shared. For example your user service is using HttpContext.Current. Well if that service is in an global application-level container, you won't get the desired result, as the single instance will get shared across all requests. &lt;/p&gt;
&lt;p&gt;This is because if it shared, MEF will only invoke the property once. However, if you change it to non-shared each call will create a new instance, which is probably what you want.&lt;/p&gt;
</description></item></channel></rss>