<?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: Dependency Injection Myth: Reference Passing</title>
	<atom:link href="http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/feed/" rel="self" type="application/rss+xml" />
	<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/</link>
	<description>Testability Explorer</description>
	<lastBuildDate>Tue, 09 Mar 2010 04:29:26 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Test Driven Development</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-2358</link>
		<dc:creator>Test Driven Development</dc:creator>
		<pubDate>Tue, 17 Nov 2009 16:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-2358</guid>
		<description>[...] way I approach programming. When to use Dependency Injection, Guide to Writing Testable Code and Dependency Injection Myth: Reference Passing are some of the blog posts that I would definitely recommend [...]</description>
		<content:encoded><![CDATA[<p>[...] way I approach programming. When to use Dependency Injection, Guide to Writing Testable Code and Dependency Injection Myth: Reference Passing are some of the blog posts that I would definitely recommend [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-1659</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Fri, 14 Aug 2009 17:24:37 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-1659</guid>
		<description>@Dave,

Logging is a weird case, because the information flows only one way, from your application to the logger. More importantly your application does not (should not behave any differently) if the logging is enabled or disabled. For this reason even thought logging is global state it will not hurt you, so I say just do Logger.getLog(...) right where you need it. However, if in your test you need to assert that a particular message did get written to a log, than you have no choice but to inject the logger through the constructor. GUICE will do this for you automatically.</description>
		<content:encoded><![CDATA[<p>@Dave,</p>
<p>Logging is a weird case, because the information flows only one way, from your application to the logger. More importantly your application does not (should not behave any differently) if the logging is enabled or disabled. For this reason even thought logging is global state it will not hurt you, so I say just do Logger.getLog(&#8230;) right where you need it. However, if in your test you need to assert that a particular message did get written to a log, than you have no choice but to inject the logger through the constructor. GUICE will do this for you automatically.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dave</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-1648</link>
		<dc:creator>dave</dc:creator>
		<pubDate>Thu, 13 Aug 2009 21:40:55 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-1648</guid>
		<description>Misko, I agree best to request dependencies in the constructor for most case but how do you suggest DI for something as ubiquitous as a logging object? Since I think you advise against factories and I don&#039;t want to cascade the logging interface request into every constructor that might log, I&#039;m at a loss on how to do this efficiently and cleanly. I&#039;m thinking about using a proxy factory that a delegate must be set into by the production or the testing application.  If you recommend using a container, how is that different from a factory and how do you normally access that container from objects which may have been instantiated by a production vs. a testing container? Again the only way I can think of is to have a container proxy which has a delegate set into it by the actual container. Maybe container and factory are really the same thing? Thanks, Dave</description>
		<content:encoded><![CDATA[<p>Misko, I agree best to request dependencies in the constructor for most case but how do you suggest DI for something as ubiquitous as a logging object? Since I think you advise against factories and I don&#8217;t want to cascade the logging interface request into every constructor that might log, I&#8217;m at a loss on how to do this efficiently and cleanly. I&#8217;m thinking about using a proxy factory that a delegate must be set into by the production or the testing application.  If you recommend using a container, how is that different from a factory and how do you normally access that container from objects which may have been instantiated by a production vs. a testing container? Again the only way I can think of is to have a container proxy which has a delegate set into it by the actual container. Maybe container and factory are really the same thing? Thanks, Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giorgio Sironi</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-1120</link>
		<dc:creator>Giorgio Sironi</dc:creator>
		<pubDate>Wed, 27 May 2009 20:53:45 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-1120</guid>
		<description>@Misko:I found your article Where have all the singletons gone?... Translating in that example, I was worried that RequestFactory has to know about everything the objects it creates need. After coding I think it makes sense, even if RequestFactory creates third-level factories to pass in the constructor of objects that absolutely need to create their dependency dinamically. My coding was on a Mapper for database tables that needs to create a table Introspector for each record and subrecord it has to save. I resolved with a IntrospectorFactory.</description>
		<content:encoded><![CDATA[<p>@Misko:I found your article Where have all the singletons gone?&#8230; Translating in that example, I was worried that RequestFactory has to know about everything the objects it creates need. After coding I think it makes sense, even if RequestFactory creates third-level factories to pass in the constructor of objects that absolutely need to create their dependency dinamically. My coding was on a Mapper for database tables that needs to create a table Introspector for each record and subrecord it has to save. I resolved with a IntrospectorFactory.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-1119</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Wed, 27 May 2009 19:15:00 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-1119</guid>
		<description>@ Ryan,

why do you need a God class? Everyone just knows what they need to know. Factory knows about everything which it is responsible for instantiating. Where does God class come in?</description>
		<content:encoded><![CDATA[<p>@ Ryan,</p>
<p>why do you need a God class? Everyone just knows what they need to know. Factory knows about everything which it is responsible for instantiating. Where does God class come in?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-1118</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Wed, 27 May 2009 17:27:43 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-1118</guid>
		<description>It looks clean, but isn&#039;t this requiring a god class that needs to create everything? If you want to create a LoginPage, you have to create a UserRepository and a Database. This becomes a pain when you move outside an example to deeper and wider dependencies.</description>
		<content:encoded><![CDATA[<p>It looks clean, but isn&#8217;t this requiring a god class that needs to create everything? If you want to create a LoginPage, you have to create a UserRepository and a Database. This becomes a pain when you move outside an example to deeper and wider dependencies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-1107</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Mon, 25 May 2009 00:12:16 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-1107</guid>
		<description>@Giorgio,

I am having a hard time follewing your example without an example code, but I think you are on the right track and what you are saying is correct.</description>
		<content:encoded><![CDATA[<p>@Giorgio,</p>
<p>I am having a hard time follewing your example without an example code, but I think you are on the right track and what you are saying is correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giorgio Sironi</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-1106</link>
		<dc:creator>Giorgio Sironi</dc:creator>
		<pubDate>Sun, 24 May 2009 16:15:42 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-1106</guid>
		<description>So it is now obvious that the application factory (or the container) holds the small-s-singleton: an instance of the Database object. What about construction of objects that have a small lifetime? For instance, a ArticleRepository could create Tag objects to send when a Article is modified; my approach is to make ArticleRepository to ask for a TagFactory in the constructor. This is an example of creation of non-newables (Song example) in the application logic, that is simply delegation to the TagFactory. It could be the same with any other object that is not created for the global application lifetime but only for a small one, and that has in the constructor some dependency to a general singleton like Database.So the TagFactory needs to hold a reference to pass to the Tag, right?</description>
		<content:encoded><![CDATA[<p>So it is now obvious that the application factory (or the container) holds the small-s-singleton: an instance of the Database object. What about construction of objects that have a small lifetime? For instance, a ArticleRepository could create Tag objects to send when a Article is modified; my approach is to make ArticleRepository to ask for a TagFactory in the constructor. This is an example of creation of non-newables (Song example) in the application logic, that is simply delegation to the TagFactory. It could be the same with any other object that is not created for the global application lifetime but only for a small one, and that has in the constructor some dependency to a general singleton like Database.So the TagFactory needs to hold a reference to pass to the Tag, right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: misko</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-848</link>
		<dc:creator>misko</dc:creator>
		<pubDate>Tue, 07 Apr 2009 10:10:55 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-848</guid>
		<description>@Darren,

You have shifted the problem to the factory. Bu that is a good thing for many reasons. (1) Separation of concerns. (2) Separating of the initialization logic from the business logic and (3) guaranteed order of initialization.</description>
		<content:encoded><![CDATA[<p>@Darren,</p>
<p>You have shifted the problem to the factory. Bu that is a good thing for many reasons. (1) Separation of concerns. (2) Separating of the initialization logic from the business logic and (3) guaranteed order of initialization.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Darren</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-847</link>
		<dc:creator>Darren</dc:creator>
		<pubDate>Tue, 07 Apr 2009 02:32:46 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-847</guid>
		<description>While I agree with the sentiment here, I think there&#039;s a bit of sleight-of-hand going on with these examples. With the Singleton example, it&#039;s obvious how the UserRepository gets its db connection - it &quot;fetches&quot; it using a call to the Singleton, which probably makes a connection to the db if it doesn&#039;t already exist. In the DI example, it&#039;s not clear how the UserRepository gets a working db connection - basically it is just saying, &quot;I&#039;m not doing anything until you give me a db connection&quot;. I suppose the assumption here is that there is some sort of DI framework or other implementation that actually injects an existing db connection. That may be, but it&#039;s misleading to say, &quot;Look how much cleaner the second example is&quot; because you have stripped out the part of the logic that actually creates and injects a db connection into the object. How do we know that you haven&#039;t just shifted the problem to some other layer of your application, eg. the DI framework?</description>
		<content:encoded><![CDATA[<p>While I agree with the sentiment here, I think there&#8217;s a bit of sleight-of-hand going on with these examples. With the Singleton example, it&#8217;s obvious how the UserRepository gets its db connection &#8211; it &#8220;fetches&#8221; it using a call to the Singleton, which probably makes a connection to the db if it doesn&#8217;t already exist. In the DI example, it&#8217;s not clear how the UserRepository gets a working db connection &#8211; basically it is just saying, &#8220;I&#8217;m not doing anything until you give me a db connection&#8221;. I suppose the assumption here is that there is some sort of DI framework or other implementation that actually injects an existing db connection. That may be, but it&#8217;s misleading to say, &#8220;Look how much cleaner the second example is&#8221; because you have stripped out the part of the logic that actually creates and injects a db connection into the object. How do we know that you haven&#8217;t just shifted the problem to some other layer of your application, eg. the DI framework?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
