<?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: Coding: Invariant checking on dependency injected components</title>
	<atom:link href="http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/</link>
	<description>Thoughts on Software Development</description>
	<lastBuildDate>Sat, 11 Feb 2012 23:17:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Kenrick Chien</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/comment-page-1/#comment-26224</link>
		<dc:creator>Kenrick Chien</dc:creator>
		<pubDate>Thu, 05 Nov 2009 12:51:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1774#comment-26224</guid>
		<description>I&#039;d say don&#039;t put the checks there.
1) If you&#039;re using an IOC, such as Spring, there is an XML attribute (dependency-check) to check that either all dependencies are injected, primitives, or objects. 
2) If you&#039;re not using an IOC, then you&#039;re going to have one class or part of the application that is wiring everything up, such as the class that contains main().  It would be very easy _not_ to make the mistake of passing in null, and on the rare chance that someone did, it&#039;s easy to spot.</description>
		<content:encoded><![CDATA[<p>I&#8217;d say don&#8217;t put the checks there.<br />
1) If you&#8217;re using an IOC, such as Spring, there is an XML attribute (dependency-check) to check that either all dependencies are injected, primitives, or objects.<br />
2) If you&#8217;re not using an IOC, then you&#8217;re going to have one class or part of the application that is wiring everything up, such as the class that contains main().  It would be very easy _not_ to make the mistake of passing in null, and on the rare chance that someone did, it&#8217;s easy to spot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Craig Wilson</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/comment-page-1/#comment-26064</link>
		<dc:creator>Craig Wilson</dc:creator>
		<pubDate>Mon, 02 Nov 2009 13:36:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1774#comment-26064</guid>
		<description>I also agree that if the IoC container provides a null value, it is a failure of the container.  However, simply because we &quot;know&quot; an IoC container will exist doesn&#039;t mean we code for it.  The benefit to an IoC container is that your classes shouldn&#039;t &quot;know&quot; it&#039;s there.  In other words, by assuming that an IoC container will inject our dependencies for us is like creating a dependency upon that IoC container that isn&#039;t present anywhere in the class.  I would say that this is worse than just newing up the dependency inside.

So, in summary.  Do the invariant checking!  Sure, it&#039;s probably not necessary, but at least things are explicit.</description>
		<content:encoded><![CDATA[<p>I also agree that if the IoC container provides a null value, it is a failure of the container.  However, simply because we &#8220;know&#8221; an IoC container will exist doesn&#8217;t mean we code for it.  The benefit to an IoC container is that your classes shouldn&#8217;t &#8220;know&#8221; it&#8217;s there.  In other words, by assuming that an IoC container will inject our dependencies for us is like creating a dependency upon that IoC container that isn&#8217;t present anywhere in the class.  I would say that this is worse than just newing up the dependency inside.</p>
<p>So, in summary.  Do the invariant checking!  Sure, it&#8217;s probably not necessary, but at least things are explicit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Ribakoff</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/comment-page-1/#comment-26063</link>
		<dc:creator>Josh Ribakoff</dc:creator>
		<pubDate>Mon, 02 Nov 2009 13:34:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1774#comment-26063</guid>
		<description>The people behind the Google testing blog wrote/said  something to the effect of, &quot;it is much better to have that code execute in a test harness&quot;

For example, now you have limited yourself from passing null values in a unit test.

For instance if youre writing a test to cover Dependency1, you shouldn&#039;t HAVE to mock out Dependency2, you should be able to just pass null to signify that no code executes, as a part of this test, that uses that instance of Dependency2 (because you would get a null pointer exception when you ran the test).

So not only is it a violation of DRY it limits your design, makes your tests harder to understand at a glance.</description>
		<content:encoded><![CDATA[<p>The people behind the Google testing blog wrote/said  something to the effect of, &#8220;it is much better to have that code execute in a test harness&#8221;</p>
<p>For example, now you have limited yourself from passing null values in a unit test.</p>
<p>For instance if youre writing a test to cover Dependency1, you shouldn&#8217;t HAVE to mock out Dependency2, you should be able to just pass null to signify that no code executes, as a part of this test, that uses that instance of Dependency2 (because you would get a null pointer exception when you ran the test).</p>
<p>So not only is it a violation of DRY it limits your design, makes your tests harder to understand at a glance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Awkward Coder</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/comment-page-1/#comment-26052</link>
		<dc:creator>Awkward Coder</dc:creator>
		<pubDate>Mon, 02 Nov 2009 10:33:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1774#comment-26052</guid>
		<description>+1 with Jeremy on this...</description>
		<content:encoded><![CDATA[<p>+1 with Jeremy on this&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Reflective Perspective - Chris Alcock &#187; The Morning Brew #467</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/comment-page-1/#comment-26044</link>
		<dc:creator>Reflective Perspective - Chris Alcock &#187; The Morning Brew #467</dc:creator>
		<pubDate>Mon, 02 Nov 2009 08:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1774#comment-26044</guid>
		<description>[...] Coding: Invariant checking on dependency injected components - Mark Needham continues discussing invariant checking, this time looking at checking on the dependencies that should be being provided by the Dependency Injection framework, asking if this is necessary, and if there is a better place to check these dependencies [...]</description>
		<content:encoded><![CDATA[<p>[...] Coding: Invariant checking on dependency injected components &#8211; Mark Needham continues discussing invariant checking, this time looking at checking on the dependencies that should be being provided by the Dependency Injection framework, asking if this is necessary, and if there is a better place to check these dependencies [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy D. Miller</title>
		<link>http://www.markhneedham.com/blog/2009/10/31/coding-invariant-checking-on-dependency-injected-components/comment-page-1/#comment-25875</link>
		<dc:creator>Jeremy D. Miller</dc:creator>
		<pubDate>Fri, 30 Oct 2009 20:28:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.markhneedham.com/blog/?p=1774#comment-25875</guid>
		<description>I&#039;d say that that&#039;s a failure of the IoC container.  Most IoC tools would throw an exception if it didn&#039;t know how to resolve a constructor dependency and fail quickly.  

Human beings should not be wasted on repetitive defensive programming checks like the Asserts above.</description>
		<content:encoded><![CDATA[<p>I&#8217;d say that that&#8217;s a failure of the IoC container.  Most IoC tools would throw an exception if it didn&#8217;t know how to resolve a constructor dependency and fail quickly.  </p>
<p>Human beings should not be wasted on repetitive defensive programming checks like the Asserts above.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

