<?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: Getting rid of IoC</title>
	<atom:link href="http://nutrun.com/weblog/getting-rid-of-ioc/feed/" rel="self" type="application/rss+xml" />
	<link>http://nutrun.com/weblog/getting-rid-of-ioc/</link>
	<description>nutrun</description>
	<lastBuildDate>Fri, 08 Jan 2010 06:54:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: David Billskog</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-189</link>
		<dc:creator>David Billskog</dc:creator>
		<pubDate>Tue, 14 Nov 2006 19:45:05 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-189</guid>
		<description>I&#039;m a bit new to dependency injection but why don&#039;t we just inject a ioc container to every class that has a dependency? We could then mock/stub the container when testing. This would also reduce the need for the extra buzz of factories everywhere we need to create objects.

Pros:
Doesn&#039;t pollute constructor with more then one parameter (replacing constructor injection).
We have a consistent use for all classes so we don&#039;t have to think about it and thus decreasing our cognitive load when programming.
We may be able to remove some factories.

Cons:
Simple classes may be a tad more complex.
It will have to be combined with a mock library.
It may be harder to understand testcases before you know the approach.

I bet there is something i have missed... :-)</description>
		<content:encoded><![CDATA[<p>I&#8217;m a bit new to dependency injection but why don&#8217;t we just inject a ioc container to every class that has a dependency? We could then mock/stub the container when testing. This would also reduce the need for the extra buzz of factories everywhere we need to create objects.</p>
<p>Pros:<br />
Doesn&#8217;t pollute constructor with more then one parameter (replacing constructor injection).<br />
We have a consistent use for all classes so we don&#8217;t have to think about it and thus decreasing our cognitive load when programming.<br />
We may be able to remove some factories.</p>
<p>Cons:<br />
Simple classes may be a tad more complex.<br />
It will have to be combined with a mock library.<br />
It may be harder to understand testcases before you know the approach.</p>
<p>I bet there is something i have missed&#8230; :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt McGill</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-188</link>
		<dc:creator>Matt McGill</dc:creator>
		<pubDate>Wed, 13 Sep 2006 19:05:10 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-188</guid>
		<description>What you&#039;re saying about polluting constructors with extra parameters is definately resonating with me, but I&#039;m still not convinced that using reflection to get at private members is such a hot idea, even in this case. Just today I&#039;ve encountered a few situations along these lines, and I fell back on using template methods to &#039;inject&#039; the desired class. Something like this:

public abstract class AbstractJimi {
   protected abstract Guitar createGuitar();
   private Guitar guitar = createGuitar();
...
}

pubilc class Jimi extends AbstractJimi {
   protected Guitar createGuitar() {
      return new Guitar();
   }
}


Still not as &#039;clean&#039; as you&#039;d like, I know, coming with the cost of an extra class. But it does allow you to mock Guitar in a unit test without reflection, and it doesn&#039;t require a factory interface/mocked factory/factory implementation trio. I think this one just comes down to preference at this point.

-Matt McGill</description>
		<content:encoded><![CDATA[<p>What you&#8217;re saying about polluting constructors with extra parameters is definately resonating with me, but I&#8217;m still not convinced that using reflection to get at private members is such a hot idea, even in this case. Just today I&#8217;ve encountered a few situations along these lines, and I fell back on using template methods to &#8216;inject&#8217; the desired class. Something like this:</p>
<p>public abstract class AbstractJimi {<br />
   protected abstract Guitar createGuitar();<br />
   private Guitar guitar = createGuitar();<br />
&#8230;<br />
}</p>
<p>pubilc class Jimi extends AbstractJimi {<br />
   protected Guitar createGuitar() {<br />
      return new Guitar();<br />
   }<br />
}</p>
<p>Still not as &#8216;clean&#8217; as you&#8217;d like, I know, coming with the cost of an extra class. But it does allow you to mock Guitar in a unit test without reflection, and it doesn&#8217;t require a factory interface/mocked factory/factory implementation trio. I think this one just comes down to preference at this point.</p>
<p>-Matt McGill</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Savage</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-187</link>
		<dc:creator>Matt Savage</dc:creator>
		<pubDate>Wed, 13 Sep 2006 09:59:19 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-187</guid>
		<description>...and the thing is it&#039;s doubly hard to do what I think is the right thing and remove the builders from the constructor (or delete the setter or whatever) if you find yourself wanting to mock them out in tests.

Which is why I originally decided that setting the things through reflection in tests was better than messing up my classes by introducing a PaymentBuilder interface with a DefaultPaymentBuilder, PaymentBuilderImpl or something equally nasty. Which also suggests that we might acutally want to replace the builder classes  with a different implementation later (which we never will, because there should only ever be one way to make a Payment from a PaymentDocument).

*takes deep breath, steps away from the keyboard*

Please excuse the huge volume of posting- I&#039;m sure this can be explained in less words.</description>
		<content:encoded><![CDATA[<p>&#8230;and the thing is it&#8217;s doubly hard to do what I think is the right thing and remove the builders from the constructor (or delete the setter or whatever) if you find yourself wanting to mock them out in tests.</p>
<p>Which is why I originally decided that setting the things through reflection in tests was better than messing up my classes by introducing a PaymentBuilder interface with a DefaultPaymentBuilder, PaymentBuilderImpl or something equally nasty. Which also suggests that we might acutally want to replace the builder classes  with a different implementation later (which we never will, because there should only ever be one way to make a Payment from a PaymentDocument).</p>
<p>*takes deep breath, steps away from the keyboard*</p>
<p>Please excuse the huge volume of posting- I&#8217;m sure this can be explained in less words.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Savage</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-186</link>
		<dc:creator>Matt Savage</dc:creator>
		<pubDate>Wed, 13 Sep 2006 09:50:23 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-186</guid>
		<description>&gt; IoC’s generally help manage configuration of the view, service and persistence layers, where interfaces and configuration are much more important.

...for which I think they&#039;re great.

&gt; Your example is a Domain object...

You&#039;re right. This is an inappropriate use of IoC, and that&#039;s the point.

A more real-world example would be this:

class&nbsp;PaymentService&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;PaymentRepository&nbsp;paymentRepository;
&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;PaymentBuilder&nbsp;paymentBuilder;
&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;MainframePaymentMessageBuilder&nbsp;mainframeMessageBuilder;
&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;MainframePaymentsService&nbsp;mainframePaymentsService;

&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;PaymentService(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PaymentBuilder&nbsp;paymentBuilder,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MainframePaymentMessageBuilder&nbsp;mainframeMessageBuilder,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PaymentRepository&nbsp;paymentRepository,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MainframePaymentsService&nbsp;mainframePaymentsService)&nbsp;{

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.paymentBuilder&nbsp;=&nbsp;paymentBuilder;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.mainframeMessageBuilder&nbsp;=&nbsp;mainframeMessageBuilder;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.paymentRepository&nbsp;=&nbsp;paymentRepository;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.mainframePaymentsService&nbsp;=&nbsp;mainframePaymentsService;

&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;makePayment(PaymentDocument&nbsp;document)&nbsp;{

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Payment&nbsp;payment&nbsp;=&nbsp;paymentBuilder.buildPaymentFrom(document);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PaymentMessage&nbsp;paymentMessage&nbsp;=&nbsp;mainframeMessageBuilder.buildPaymentMessage(payment);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mainframePaymentsService.makePayment(paymentMessage);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paymentRepository.save(payment);

&nbsp;&nbsp;&nbsp;&nbsp;}
}

In this instance (which is a _simplified_ real-world example- and please ignore all the irrelevant bad things in the design of this class) there&#039;s absolutely no need to inject the builders. The repository and the other service, yes, but not the builders.

It&#039;s so, SO easy to forget that what you&#039;re injecting is a domain object (see: FooBuilder example in my comment above). I for one have had to stop myself a couple of times automatically adding another constructor argument for something that should only ever have one implementation anywhere in the system. The smell here is seeing what should be domain objects with a single implementation popping up in your IoC container config.


&gt; I think the post is a little bit extreme.

The title of the post is extreme, this: &quot;What I’m saying is: Use IoC when you need it and use it for what it’s for.&quot; is probably more like it.</description>
		<content:encoded><![CDATA[<p>&#38;gt; IoC’s generally help manage configuration of the view, service and persistence layers, where interfaces and configuration are much more important.</p>
<p>&#8230;for which I think they&#8217;re great.</p>
<p>&#38;gt; Your example is a Domain object&#8230;</p>
<p>You&#8217;re right. This is an inappropriate use of IoC, and that&#8217;s the point.</p>
<p>A more real-world example would be this:</p>
<p>class&#38;nbsp;PaymentService&#38;nbsp;{<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;private&#38;nbsp;PaymentRepository&#38;nbsp;paymentRepository;<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;private&#38;nbsp;PaymentBuilder&#38;nbsp;paymentBuilder;<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;private&#38;nbsp;MainframePaymentMessageBuilder&#38;nbsp;mainframeMessageBuilder;<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;private&#38;nbsp;MainframePaymentsService&#38;nbsp;mainframePaymentsService;</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;public&#38;nbsp;PaymentService(<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;PaymentBuilder&#38;nbsp;paymentBuilder,<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;MainframePaymentMessageBuilder&#38;nbsp;mainframeMessageBuilder,<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;PaymentRepository&#38;nbsp;paymentRepository,<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;MainframePaymentsService&#38;nbsp;mainframePaymentsService)&#38;nbsp;{</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;this.paymentBuilder&#38;nbsp;=&#38;nbsp;paymentBuilder;<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;this.mainframeMessageBuilder&#38;nbsp;=&#38;nbsp;mainframeMessageBuilder;</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;this.paymentRepository&#38;nbsp;=&#38;nbsp;paymentRepository;<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;this.mainframePaymentsService&#38;nbsp;=&#38;nbsp;mainframePaymentsService;</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;}</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;public&#38;nbsp;void&#38;nbsp;makePayment(PaymentDocument&#38;nbsp;document)&#38;nbsp;{</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;Payment&#38;nbsp;payment&#38;nbsp;=&#38;nbsp;paymentBuilder.buildPaymentFrom(document);<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;PaymentMessage&#38;nbsp;paymentMessage&#38;nbsp;=&#38;nbsp;mainframeMessageBuilder.buildPaymentMessage(payment);</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;mainframePaymentsService.makePayment(paymentMessage);<br />
&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;paymentRepository.save(payment);</p>
<p>&#38;nbsp;&#38;nbsp;&#38;nbsp;&#38;nbsp;}<br />
}</p>
<p>In this instance (which is a _simplified_ real-world example- and please ignore all the irrelevant bad things in the design of this class) there&#8217;s absolutely no need to inject the builders. The repository and the other service, yes, but not the builders.</p>
<p>It&#8217;s so, SO easy to forget that what you&#8217;re injecting is a domain object (see: FooBuilder example in my comment above). I for one have had to stop myself a couple of times automatically adding another constructor argument for something that should only ever have one implementation anywhere in the system. The smell here is seeing what should be domain objects with a single implementation popping up in your IoC container config.</p>
<p>&#38;gt; I think the post is a little bit extreme.</p>
<p>The title of the post is extreme, this: &#8220;What I’m saying is: Use IoC when you need it and use it for what it’s for.&#8221; is probably more like it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Savage</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-185</link>
		<dc:creator>Matt Savage</dc:creator>
		<pubDate>Wed, 13 Sep 2006 09:46:48 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-185</guid>
		<description>[Testing whether I can use &nbsp; characters to format code]</description>
		<content:encoded><![CDATA[<p>[Testing whether I can use &#38;nbsp; characters to format code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-184</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Tue, 12 Sep 2006 15:00:21 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-184</guid>
		<description>I am suspicious of someone saying Jimi will always play a guitar.

If he were alive today we may have seen him do some interesting things with other instruments.  I certainly bet he would not like to discover he had been constrained such that he could only ever play one instrument.

It is kind of like the hammer thing.  If you get told that every problem in the world must be solved with a hammer then you are less likely to think about that screwdriver in the corner.</description>
		<content:encoded><![CDATA[<p>I am suspicious of someone saying Jimi will always play a guitar.</p>
<p>If he were alive today we may have seen him do some interesting things with other instruments.  I certainly bet he would not like to discover he had been constrained such that he could only ever play one instrument.</p>
<p>It is kind of like the hammer thing.  If you get told that every problem in the world must be solved with a hammer then you are less likely to think about that screwdriver in the corner.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Solomon</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-183</link>
		<dc:creator>Solomon</dc:creator>
		<pubDate>Tue, 12 Sep 2006 13:30:31 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-183</guid>
		<description>FYI... I have a trackback (When to user IoC) at http://jroller.com/page/Solomon?entry=when_to_use_ioc

Javalobby: (Is IoC / Dependency Injection Overated?) http://www.javalobby.org/java/forums/t78371.html

I have a question about your entry:

1) Do you really think that people advocate &quot;thou shalt use an IoC container EVERYWHERE?&quot;  Even if some do, I would suspect that the majority of pro-IoC container developers don’t think that it’s useful EVERYWHERE.

2) What kind of container do you recommend for large projects?  J2EE containers came about because of a need for containers in LARGE project.  Heck, even Tiles has a container...  You need some method of managing dependencies.

3) Your example is a Domain object.  IoC&#039;s generally help manage configuration of the view, service and persistence layers, where interfaces and configuration are much more important.  IoC/AOP in the Domain layer is most definitely a controversial.  What exactly was your intention by using a domain-type argument?  Was it to prove that IoC is overrated or that IoC is not applicable for THAT particular case?

I personally like what IoC and IoC Containers can do for me.  They do pay the bills right now.  However, I’m always on the lookout for other advancements in technology theory and practical use.  I’m also looking for clearly stated “best practices” types of advice and discussions as to when to use something and when not to use something.  IMHO, IoC Container (and specifically Spring Framework) “best practices” are still emerging even after almost three years of IoC being in the lime-light.

With that said, thanks for the post.  It definitely brought about some interesting discussions.</description>
		<content:encoded><![CDATA[<p>FYI&#8230; I have a trackback (When to user IoC) at <a href="http://jroller.com/page/Solomon?entry=when_to_use_ioc" rel="nofollow">http://jroller.com/page/Solomon?entry=when_to_use_ioc</a></p>
<p>Javalobby: (Is IoC / Dependency Injection Overated?) <a href="http://www.javalobby.org/java/forums/t78371.html" rel="nofollow">http://www.javalobby.org/java/forums/t78371.html</a></p>
<p>I have a question about your entry:</p>
<p>1) Do you really think that people advocate &#8220;thou shalt use an IoC container EVERYWHERE?&#8221;  Even if some do, I would suspect that the majority of pro-IoC container developers don’t think that it’s useful EVERYWHERE.</p>
<p>2) What kind of container do you recommend for large projects?  J2EE containers came about because of a need for containers in LARGE project.  Heck, even Tiles has a container&#8230;  You need some method of managing dependencies.</p>
<p>3) Your example is a Domain object.  IoC&#8217;s generally help manage configuration of the view, service and persistence layers, where interfaces and configuration are much more important.  IoC/AOP in the Domain layer is most definitely a controversial.  What exactly was your intention by using a domain-type argument?  Was it to prove that IoC is overrated or that IoC is not applicable for THAT particular case?</p>
<p>I personally like what IoC and IoC Containers can do for me.  They do pay the bills right now.  However, I’m always on the lookout for other advancements in technology theory and practical use.  I’m also looking for clearly stated “best practices” types of advice and discussions as to when to use something and when not to use something.  IMHO, IoC Container (and specifically Spring Framework) “best practices” are still emerging even after almost three years of IoC being in the lime-light.</p>
<p>With that said, thanks for the post.  It definitely brought about some interesting discussions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-182</link>
		<dc:creator>Pat</dc:creator>
		<pubDate>Tue, 12 Sep 2006 13:13:31 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-182</guid>
		<description>Though I think I understand what George is trying to say, I think the post is a little bit extreme.

I dislike the example above because the dependency injected looks more like state based DI instead of role based DI.

One tangible benefit I have seen using DI properly is that I can move aspects from one implementing class to another, and I don&#039;t break any consumers. In the above example, if I moved the role that the Guitar actually played to another class, I would be forced to change the Rock class (blech!).</description>
		<content:encoded><![CDATA[<p>Though I think I understand what George is trying to say, I think the post is a little bit extreme.</p>
<p>I dislike the example above because the dependency injected looks more like state based DI instead of role based DI.</p>
<p>One tangible benefit I have seen using DI properly is that I can move aspects from one implementing class to another, and I don&#8217;t break any consumers. In the above example, if I moved the role that the Guitar actually played to another class, I would be forced to change the Rock class (blech!).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Savage</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-181</link>
		<dc:creator>Matt Savage</dc:creator>
		<pubDate>Tue, 12 Sep 2006 10:05:29 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-181</guid>
		<description>To be clear,

(and George, please correct me if I&#039;m misrepresenting you)

1. Nobody&#039;s advocating using this technique anywhere other than in unit tests.
2. Nobody&#039;s suggesting there isn&#039;t a place for IoC containers, just that wiring up everything and its dog in Spring IoC is often overkill.

What George is talking about is things a bit like this:

class Jimi {
    private Instrument instrument;

    public Jimi(Instrument instrument) {
        this.instrument = instrument;
    }
}

We all know Jimi&#039;s always going to play guitar. If Jimi&#039;s not playing guitar, that&#039;s not really what we wanted. So why bother exposing it? Why not just say:

class Jimi {
    private Instrument instrument = new Geetar();

    public Jimi() {
    }
}

We&#039;ve expressed the intent that Jimi should ALWAYS play guitar. We&#039;ve avoided some more unnecessary configuration in our IoC container.

This is all to the good, shurely?

A better, real-world example would be a service that uses a builder to create one object from another (a Foo from a Bar). It&#039;s a reasonable expectation that there will only ever be one way you can make a Foo from a Bar in your system. So why bother injecting the builder into your service? Why bother even suggesting there will ever be another type of builder in your container configuration?

What I like about George&#039;s post is that he&#039;s challenging all those well-ingrained architectural decisions we make (thou shalt use an IoC container EVERYWHERE) and pointing out that actually, a lot of the time, we make more work for ourselves like this.

Sometimes this is a bad idea on the basis that it&#039;s better to have a consistent architecture that leads to over-engineering in some places. On the project we&#039;ve just come off, I don&#039;t think that was the case and this technique worked well for us.</description>
		<content:encoded><![CDATA[<p>To be clear,</p>
<p>(and George, please correct me if I&#8217;m misrepresenting you)</p>
<p>1. Nobody&#8217;s advocating using this technique anywhere other than in unit tests.<br />
2. Nobody&#8217;s suggesting there isn&#8217;t a place for IoC containers, just that wiring up everything and its dog in Spring IoC is often overkill.</p>
<p>What George is talking about is things a bit like this:</p>
<p>class Jimi {<br />
    private Instrument instrument;</p>
<p>    public Jimi(Instrument instrument) {<br />
        this.instrument = instrument;<br />
    }<br />
}</p>
<p>We all know Jimi&#8217;s always going to play guitar. If Jimi&#8217;s not playing guitar, that&#8217;s not really what we wanted. So why bother exposing it? Why not just say:</p>
<p>class Jimi {<br />
    private Instrument instrument = new Geetar();</p>
<p>    public Jimi() {<br />
    }<br />
}</p>
<p>We&#8217;ve expressed the intent that Jimi should ALWAYS play guitar. We&#8217;ve avoided some more unnecessary configuration in our IoC container.</p>
<p>This is all to the good, shurely?</p>
<p>A better, real-world example would be a service that uses a builder to create one object from another (a Foo from a Bar). It&#8217;s a reasonable expectation that there will only ever be one way you can make a Foo from a Bar in your system. So why bother injecting the builder into your service? Why bother even suggesting there will ever be another type of builder in your container configuration?</p>
<p>What I like about George&#8217;s post is that he&#8217;s challenging all those well-ingrained architectural decisions we make (thou shalt use an IoC container EVERYWHERE) and pointing out that actually, a lot of the time, we make more work for ourselves like this.</p>
<p>Sometimes this is a bad idea on the basis that it&#8217;s better to have a consistent architecture that leads to over-engineering in some places. On the project we&#8217;ve just come off, I don&#8217;t think that was the case and this technique worked well for us.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus Ahnve</title>
		<link>http://nutrun.com/weblog/getting-rid-of-ioc/comment-page-1/#comment-180</link>
		<dc:creator>Marcus Ahnve</dc:creator>
		<pubDate>Tue, 12 Sep 2006 06:40:31 +0000</pubDate>
		<guid isPermaLink="false">http://new-site.nutrun.com/?p=51#comment-180</guid>
		<description>While I agree with with the &quot;use IoC for what its for&quot;, in my opinion IoC is not about changing implementations. It is all about getting rid of dependencies, which in turn enables modularized code.

I normally encourage the use of IoC between layers, so that the view layer does not access the logic layer directly etc. IoC within layers is normally overkill.</description>
		<content:encoded><![CDATA[<p>While I agree with with the &#8220;use IoC for what its for&#8221;, in my opinion IoC is not about changing implementations. It is all about getting rid of dependencies, which in turn enables modularized code.</p>
<p>I normally encourage the use of IoC between layers, so that the view layer does not access the logic layer directly etc. IoC within layers is normally overkill.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
