<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: The religion of dependency injection</title>
	<atom:link href="http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/</link>
	<description>Strong opinions, weakly held</description>
	<lastBuildDate>Sun, 19 May 2013 03:22:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Steve</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2442</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Mon, 24 May 2010 12:30:05 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2442</guid>
		<description>@Jeremy,

I&#039;ll take your word for it as I haven&#039;t dug deep in the MVC code, the 50% number just jumped off the page as such a huge number, I just can&#039;t fathom how that&#039;d even be possible.  

But, MVC is a complex beast, so I shouldn&#039;t be surprised that a bad design decision can start causing problems exponentially and before you know it they&#039;ve got thousands of lines of horrible code used to get around a problem.</description>
		<content:encoded><![CDATA[<p>@Jeremy,</p>
<p>I&#8217;ll take your word for it as I haven&#8217;t dug deep in the MVC code, the 50% number just jumped off the page as such a huge number, I just can&#8217;t fathom how that&#8217;d even be possible.  </p>
<p>But, MVC is a complex beast, so I shouldn&#8217;t be surprised that a bad design decision can start causing problems exponentially and before you know it they&#8217;ve got thousands of lines of horrible code used to get around a problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2441</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 24 May 2010 00:12:43 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2441</guid>
		<description>Poor man&#039;s DI is pretty insidious.  If you&#039;re working in a codebase where &#039;proper&#039; constructor injection is used and maybe 1/20 classes uses poor man&#039;s DI, then you have a problem.  Everything is configurable and loosely coupled except ... for that one type that is flying under the radar.  

I&#039;ve used constructor injection for over two years, but when I first started using an IoC container (a colleague introduced it into our application) I didn&#039;t understand it at all.  I was sceptical and thought it offered very little over normal construction.  I was so badly wrong.  The caveat is that you only get the benefits if it&#039;s set up properly, you use a consistent mechanism of obtaining types (read: use the container!) and all of the types involved play ball.(don&#039;t use new for dependencies, don&#039;t use poor man&#039;s DI etc.)

When you stumble upon a portion of your application that is going against the grain, it is tremendously irritating.  We recently encountered a situation where our application had some functionality that was manually wired up (extensive use of new, static factories and poor man&#039;s DI) which wrested control away from the container and did not go with the conventions.  

I was meant to re-use the functionality in a slightly different context, but couldn&#039;t.  The result was that we couldn&#039;t wire it up, configure or re-use the modules.  I.e. it was not loosely coupled; it was like a little enclave of hard-wired stuff.  

After they were refactored properly, the problem disappeared and all of the renegade functionality fell into line once more.  I included the module, configured it differently and it worked beautifully.</description>
		<content:encoded><![CDATA[<p>Poor man&#8217;s DI is pretty insidious.  If you&#8217;re working in a codebase where &#8216;proper&#8217; constructor injection is used and maybe 1/20 classes uses poor man&#8217;s DI, then you have a problem.  Everything is configurable and loosely coupled except &#8230; for that one type that is flying under the radar.  </p>
<p>I&#8217;ve used constructor injection for over two years, but when I first started using an IoC container (a colleague introduced it into our application) I didn&#8217;t understand it at all.  I was sceptical and thought it offered very little over normal construction.  I was so badly wrong.  The caveat is that you only get the benefits if it&#8217;s set up properly, you use a consistent mechanism of obtaining types (read: use the container!) and all of the types involved play ball.(don&#8217;t use new for dependencies, don&#8217;t use poor man&#8217;s DI etc.)</p>
<p>When you stumble upon a portion of your application that is going against the grain, it is tremendously irritating.  We recently encountered a situation where our application had some functionality that was manually wired up (extensive use of new, static factories and poor man&#8217;s DI) which wrested control away from the container and did not go with the conventions.  </p>
<p>I was meant to re-use the functionality in a slightly different context, but couldn&#8217;t.  The result was that we couldn&#8217;t wire it up, configure or re-use the modules.  I.e. it was not loosely coupled; it was like a little enclave of hard-wired stuff.  </p>
<p>After they were refactored properly, the problem disappeared and all of the renegade functionality fell into line once more.  I included the module, configured it differently and it worked beautifully.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Theo Andersen</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2440</link>
		<dc:creator>Theo Andersen</dc:creator>
		<pubDate>Sat, 22 May 2010 17:57:42 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2440</guid>
		<description>I&#039;m still not sure i get why PMDI is always such a bad thing.

What if you know that the class is always going to be using a specific implementation of the interface, but you don&#039;t want the client code to know about this implementation? (but you still want the DI to be able to decouple the dependency in tests)

Or is it wrong to use the PMDI because you don&#039;t want every code using instantiating the class to create the same code implementing the interface. The code you say is &#039;saved&#039; in the real DI, is only added to the instantiating code. Unless you would always use an IOCC.

Sorry if i&#039;m a bit slow here - I get that its not optimal with the constructor having the strong dependency, but you need to have the real coupling somewhere :) Would you then always instantiate it in the client code / IOCC.

If I&#039;m opening too big a topic here, then feel free to post links to more info .:) it&#039;s a very interesting topic.

Thanks</description>
		<content:encoded><![CDATA[<p>I&#8217;m still not sure i get why PMDI is always such a bad thing.</p>
<p>What if you know that the class is always going to be using a specific implementation of the interface, but you don&#8217;t want the client code to know about this implementation? (but you still want the DI to be able to decouple the dependency in tests)</p>
<p>Or is it wrong to use the PMDI because you don&#8217;t want every code using instantiating the class to create the same code implementing the interface. The code you say is &#8216;saved&#8217; in the real DI, is only added to the instantiating code. Unless you would always use an IOCC.</p>
<p>Sorry if i&#8217;m a bit slow here &#8211; I get that its not optimal with the constructor having the strong dependency, but you need to have the real coupling somewhere <img src='http://lostechies.com/jimmybogard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Would you then always instantiate it in the client code / IOCC.</p>
<p>If I&#8217;m opening too big a topic here, then feel free to post links to more info .:) it&#8217;s a very interesting topic.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy D. Miller</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2439</link>
		<dc:creator>Jeremy D. Miller</dc:creator>
		<pubDate>Fri, 21 May 2010 21:01:50 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2439</guid>
		<description>@steve,

I think the 50% figure is a bit high, but it isn&#039;t just because of a few extra constructors.  They&#039;re cutting a lot of public properties for unit testing through setter injection that do the &quot;if null, return the default&quot; anti pattern from years back, which in turn begets yet more [SuppressMessage] noise.

One of the other usages of an IoC container is to put things together, and they generally take care of lifecycle and scoping issues like objects that need to be scoped to a particular HttpContext or request.  The MVC code doesn&#039;t take advantage of this, and because of it, they need to write a lot more code to pass objects down inside an object graph to where it&#039;s needed.  *That&#039;s* a bigger culprit for the &quot;too much code&quot; issue than the poor man&#039;s DI.



</description>
		<content:encoded><![CDATA[<p>@steve,</p>
<p>I think the 50% figure is a bit high, but it isn&#8217;t just because of a few extra constructors.  They&#8217;re cutting a lot of public properties for unit testing through setter injection that do the &#8220;if null, return the default&#8221; anti pattern from years back, which in turn begets yet more [SuppressMessage] noise.</p>
<p>One of the other usages of an IoC container is to put things together, and they generally take care of lifecycle and scoping issues like objects that need to be scoped to a particular HttpContext or request.  The MVC code doesn&#8217;t take advantage of this, and because of it, they need to write a lot more code to pass objects down inside an object graph to where it&#8217;s needed.  *That&#8217;s* a bigger culprit for the &#8220;too much code&#8221; issue than the poor man&#8217;s DI.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Travis Calder</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2438</link>
		<dc:creator>Travis Calder</dc:creator>
		<pubDate>Fri, 21 May 2010 19:52:44 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2438</guid>
		<description>@Gabe

&#039;The Gang of Four principle is &quot;encapsulate the concept that varies&quot;.&#039;

How often do you honestly know what is going to actually vary a month from now? How about a year from now? Or ten years, assuming you&#039;re writing valuable long-lived software?

I agree with the Gang of Four principle. Encapsulate the concepts that vary, or are likely to vary. I just can&#039;t help but point out that, in any given code-base, literally everything tends to vary over time.

What you call &quot;runaway DI&quot;, I call extremely modular testable code that is predictable and loosely coupled. The &quot;poor man&#039;s DI&quot; that was illustrated in this article would provide no value to me. I may as well not DI at all, because it actually ensures that components can (and will) be constructed instead of injected. This leads to tight coupling that can slow down development cycles, inhibit testing, and just plain make my day bad.

Others may have other experiences, and your mileage may vary, but I think it&#039;s far past &quot;religious debate&quot; at this point. The strengths and weaknesses are well known, and it&#039;s just an honest professional discussion on how far each of us believes is appropriate.</description>
		<content:encoded><![CDATA[<p>@Gabe</p>
<p>&#8216;The Gang of Four principle is &#8220;encapsulate the concept that varies&#8221;.&#8217;</p>
<p>How often do you honestly know what is going to actually vary a month from now? How about a year from now? Or ten years, assuming you&#8217;re writing valuable long-lived software?</p>
<p>I agree with the Gang of Four principle. Encapsulate the concepts that vary, or are likely to vary. I just can&#8217;t help but point out that, in any given code-base, literally everything tends to vary over time.</p>
<p>What you call &#8220;runaway DI&#8221;, I call extremely modular testable code that is predictable and loosely coupled. The &#8220;poor man&#8217;s DI&#8221; that was illustrated in this article would provide no value to me. I may as well not DI at all, because it actually ensures that components can (and will) be constructed instead of injected. This leads to tight coupling that can slow down development cycles, inhibit testing, and just plain make my day bad.</p>
<p>Others may have other experiences, and your mileage may vary, but I think it&#8217;s far past &#8220;religious debate&#8221; at this point. The strengths and weaknesses are well known, and it&#8217;s just an honest professional discussion on how far each of us believes is appropriate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Davis</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2437</link>
		<dc:creator>Jon Davis</dc:creator>
		<pubDate>Fri, 21 May 2010 19:12:14 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2437</guid>
		<description>Regarding the comments above about whether to call it &quot;dependency injection&quot; or &quot;inversion of control&quot;, you guys need to slow down and pay attention to what you&#039;re saying. DI and IoC go hand-in-hand but they are far from synonymous. Dependency injection is a pattern that says &quot;I don&#039;t know the implementation of this interface, but I need this interface here, because I&#039;m going to call it. Please provide said implementation for me, please. Thanks.&quot; Inversion of control, on the other hand, looks at the problem from the opposite perspective. It says, &quot;I don&#039;t know what to do here, I need someone else to do this for me. So I&#039;m going to *invoke* this interface, or raise this event, or just set a state, and hopefully someone will finish the job.&quot; Meanwhile, someone else comes along and says, &quot;Ah, yes, I know what to do with you. Come on buddy, I&#039;ll take care of you.&quot; 

In other words, dependency injection is providing the implementor, whereas inversion of control is invoking an implementor.</description>
		<content:encoded><![CDATA[<p>Regarding the comments above about whether to call it &#8220;dependency injection&#8221; or &#8220;inversion of control&#8221;, you guys need to slow down and pay attention to what you&#8217;re saying. DI and IoC go hand-in-hand but they are far from synonymous. Dependency injection is a pattern that says &#8220;I don&#8217;t know the implementation of this interface, but I need this interface here, because I&#8217;m going to call it. Please provide said implementation for me, please. Thanks.&#8221; Inversion of control, on the other hand, looks at the problem from the opposite perspective. It says, &#8220;I don&#8217;t know what to do here, I need someone else to do this for me. So I&#8217;m going to *invoke* this interface, or raise this event, or just set a state, and hopefully someone will finish the job.&#8221; Meanwhile, someone else comes along and says, &#8220;Ah, yes, I know what to do with you. Come on buddy, I&#8217;ll take care of you.&#8221; </p>
<p>In other words, dependency injection is providing the implementor, whereas inversion of control is invoking an implementor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2436</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Fri, 21 May 2010 18:04:30 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2436</guid>
		<description>@Steve

Pop open the code, and check out how much of it is passing stuff around, context objects everywhere, factories, static gateways, etc etc.  It&#039;s a LOT of extra code that just wires things up versus actually adding behavior.  PMDI alone doesn&#039;t add extra code, it&#039;s NOT doing DI that adds all that extra code, sorry I wasn&#039;t clear about that.</description>
		<content:encoded><![CDATA[<p>@Steve</p>
<p>Pop open the code, and check out how much of it is passing stuff around, context objects everywhere, factories, static gateways, etc etc.  It&#8217;s a LOT of extra code that just wires things up versus actually adding behavior.  PMDI alone doesn&#8217;t add extra code, it&#8217;s NOT doing DI that adds all that extra code, sorry I wasn&#8217;t clear about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2435</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 21 May 2010 17:45:02 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2435</guid>
		<description>Chad Myers posted about poor man&#039;s dependency injection--I found it enlightening in that it uses an example to show how PMDI can be painful further down the road:

http://www.lostechies.com/blogs/chad_myers/archive/2009/07/14/the-usual-result-of-poor-man-s-dependency-injection.aspx</description>
		<content:encoded><![CDATA[<p>Chad Myers posted about poor man&#8217;s dependency injection&#8211;I found it enlightening in that it uses an example to show how PMDI can be painful further down the road:</p>
<p><a href="http://www.lostechies.com/blogs/chad_myers/archive/2009/07/14/the-usual-result-of-poor-man-s-dependency-injection.aspx" rel="nofollow">http://www.lostechies.com/blogs/chad_myers/archive/2009/07/14/the-usual-result-of-poor-man-s-dependency-injection.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2434</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Fri, 21 May 2010 17:18:34 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2434</guid>
		<description>50% more code because they don&#039;t think about DI?   How&#039;s that even possible?  Adding a second constructor can&#039;t account for 50% more code.  Especially considering that you then don&#039;t need any bootstrap/config code.

Listen, I&#039;m pro-DI/IoC, but we really have got to stop over exaggerating in an attempt to scare people into doing it.    </description>
		<content:encoded><![CDATA[<p>50% more code because they don&#8217;t think about DI?   How&#8217;s that even possible?  Adding a second constructor can&#8217;t account for 50% more code.  Especially considering that you then don&#8217;t need any bootstrap/config code.</p>
<p>Listen, I&#8217;m pro-DI/IoC, but we really have got to stop over exaggerating in an attempt to scare people into doing it.    </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bogardj</title>
		<link>http://lostechies.com/jimmybogard/2010/05/20/the-religion-of-dependency-injection/#comment-2433</link>
		<dc:creator>bogardj</dc:creator>
		<pubDate>Fri, 21 May 2010 12:22:57 +0000</pubDate>
		<guid isPermaLink="false">/blogs/jimmy_bogard/archive/2010/05/20/the-religion-of-dependency-injection.aspx#comment-2433</guid>
		<description>@rob

I&#039;m only coupled to the interface now, not the implementation.  That&#039;s what I&#039;m trying to achieve.  With DI, WHAT I&#039;m coupled to is explicit, and called out in the constructor.  That&#039;s why I put DI in place on the first day of a project, it makes the coupling explicit.</description>
		<content:encoded><![CDATA[<p>@rob</p>
<p>I&#8217;m only coupled to the interface now, not the implementation.  That&#8217;s what I&#8217;m trying to achieve.  With DI, WHAT I&#8217;m coupled to is explicit, and called out in the constructor.  That&#8217;s why I put DI in place on the first day of a project, it makes the coupling explicit.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
