<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Holsee&#039;s Blog &#187; PRISM</title>
	<atom:link href="http://www.blog.holsee.com/tag/prism/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.holsee.com</link>
	<description>Adventures in Entrepreneurship, Code, Coffee and Photography..</description>
	<lastBuildDate>Fri, 02 Jul 2010 10:48:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>D.I. Container &#8216;Resolve Self&#8217; &#8211; The How &amp; Why not!</title>
		<link>http://www.blog.holsee.com/2009/12/d-i-container-resolve-self-the-how-why-not/</link>
		<comments>http://www.blog.holsee.com/2009/12/d-i-container-resolve-self-the-how-why-not/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 11:36:27 +0000</pubDate>
		<dc:creator>holsee</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[PRISM]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.blog.holsee.com/2009/12/d-i-container-resolve-self-the-how-why-not/</guid>
		<description><![CDATA[Recently I was wondering how PRISM (Composite Application Guidance for WPF &#38; Silverlight) achieved a magic trick with its dependency injection (DI) container.
I knew in PRISM you are free to swop in your own DI container, which is nice but I was wondering how you achieved the trick of having your container available within itself.
What [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was wondering how <a href="http://www.codeplex.com/CompositeWPF/" target="_blank">PRISM (Composite Application Guidance for WPF &amp; Silverlight)</a> achieved a magic trick with its dependency injection (DI) container.</p>
<p>I knew in PRISM you are free to swop in your own DI container, which is nice but I was wondering how you achieved the trick of having your container <strong>available within itself</strong>.</p>
<p>What do I mean?&#160; Put simple being able to resolve your DI Container in any class within your application.</p>
<p>Example: Where ‘Foo’ is just a plain old class within the application.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Foo <span style="color: #008000;">:</span> IFoo
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> Bar SomeProp <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> Foo<span style="color: #000000;">&#40;</span>IContainer container<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		Bar <span style="color: #008000;">=</span> container.<span style="color: #0000FF;">Resolve</span><span style="color: #008000;">&lt;</span>ibar<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>		
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So I asked <a href="http://blogs.msdn.com/gblock" target="_blank">Glenn Block</a> (one of the main guys behind PRISM at Microsoft) on <a href="http://twitter.com/gblock" target="_blank">Twitter</a> how this was achieved and he got back to me with some great material which I thought I would share:</p>
<ul>
<li>How to resolve a DI Container in Unity from itself. </li>
<li>Why this is bad. </li>
<li>How to do it but limiting the badness. </li>
</ul>
<p>Note: Remember to read these ‘Blocks’ of tweets backwards as it is Twitter. So with 1 &amp; 3 start at the bottom and read up.</p>
<p align="center">0 &#8211; Me:</p>
<p align="center">&#160;<a href="http://www.blog.holsee.com/wp-content/uploads/2009/12/image.png"><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://www.blog.holsee.com/wp-content/uploads/2009/12/image_thumb.png" width="429" height="84" /></a> </p>
<p align="center">1 &#8211; GBlock:</p>
<p align="center">&#160;<a href="http://www.blog.holsee.com/wp-content/uploads/2009/12/image1.png"><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://www.blog.holsee.com/wp-content/uploads/2009/12/image_thumb1.png" width="429" height="386" /></a> </p>
<p align="center">(START FROM THE BOTTOM &amp; READ UP)</p>
<p align="center">2 &#8211; Me:</p>
<p align="center">&#160;<a href="http://www.blog.holsee.com/wp-content/uploads/2009/12/image2.png"><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://www.blog.holsee.com/wp-content/uploads/2009/12/image_thumb2.png" width="431" height="77" /></a> </p>
<p align="center">
  <br />3 &#8211; GBlock:</p>
<p align="center">&#160;<a href="http://www.blog.holsee.com/wp-content/uploads/2009/12/image3.png"><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://www.blog.holsee.com/wp-content/uploads/2009/12/image_thumb3.png" width="437" height="298" /></a> </p>
<p align="center">4 &#8211; Me:</p>
<p align="center">&#160;<a href="http://www.blog.holsee.com/wp-content/uploads/2009/12/image4.png"><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://www.blog.holsee.com/wp-content/uploads/2009/12/image_thumb4.png" width="440" height="75" /></a></p>
<p align="left">So the recommendation is to not program against the container as “It makes parts tightly coupled to host configuration” &amp; “makes code less intentful”.</p>
<p align="left">But as with the deign of modular composition frameworks such as PRISM I found it to be a good fit and it allowed for “reasonably” rapid development of the UI and decoupling of the parts of the View &amp; ViewModel that really mattered.&#160; So I see why it was suggested, but I now also see why they now see it as an anti-pattern.</p>
<p align="left">The universal access to the Container and the Event Aggregator with Composite Events made for very easy composition of a WPF user interface from separate modules, but I would have to agree, now that I have more experience, that programming against the container at this level just felt wrong deep down, and when that is the case you know its just not meant to be.</p>
<p align="left">Please feel free to comment. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.holsee.com/2009/12/d-i-container-resolve-self-the-how-why-not/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
