<?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>Fri, 30 Jul 2010 03:59:03 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Singleton &#171; Blog HM</title>
		<link>http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/comment-page-1/#comment-3792</link>
		<dc:creator>Singleton &#171; Blog HM</dc:creator>
		<pubDate>Sun, 25 Jul 2010 13:56:56 +0000</pubDate>
		<guid isPermaLink="false">http://misko.hevery.com/?p=252#comment-3792</guid>
		<description>[...] Nếu tính chất “Singleton” không phải là bản chất của class, mà là do class dùng nó yêu cầu thế, thì tính duy nhất nên được hiện thực theo một cách độc lập, như Factory Method hay Dependency Injection. [...]</description>
		<content:encoded><![CDATA[<p>[...] Nếu tính chất “Singleton” không phải là bản chất của class, mà là do class dùng nó yêu cầu thế, thì tính duy nhất nên được hiện thực theo một cách độc lập, như Factory Method hay Dependency Injection. [...]</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>
