<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: The simplest form of configurable Dependency Injection</title>
	<atom:link href="http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/feed/" rel="self" type="application/rss+xml" />
	<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 14:35:30 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Tuomas Hietanen</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1160</link>
		<dc:creator><![CDATA[Tuomas Hietanen]]></dc:creator>
		<pubDate>Tue, 19 May 2009 14:43:31 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1160</guid>
		<description><![CDATA[Nice! Like this web.config can easily be capsulated in unit-testing:

public static Func GetConfigValue = s =&gt; ConfigurationManager.AppSettings[s];]]></description>
		<content:encoded><![CDATA[<p>Nice! Like this web.config can easily be capsulated in unit-testing:</p>
<p>public static Func GetConfigValue = s =&gt; ConfigurationManager.AppSettings[s];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian Markbåge</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1148</link>
		<dc:creator><![CDATA[Sebastian Markbåge]]></dc:creator>
		<pubDate>Fri, 08 May 2009 19:34:16 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1148</guid>
		<description><![CDATA[&gt;&gt; So injecting a connection from the outside into the command object _is_ dependency injection, and that is exactly what is happening inside the GetCommand method.

I see what you mean. I was focusing on the consumer of the Config factory. Which is NOT using dependency injection. But, yea the sample implementation is using DI. And that&#039;s your point.

What is confusing is that this pattern is really about the resolver. Only the implementation is using DI. Some test implementation may create a IDbCommand that isn&#039;t using a connection. You could easily strip this pattern of DI. You could also do all this DI stuff even without the resolver.

So I would still argue that this article is about a locator/resolver and not DI per say. But since you&#039;re doing it specifically as a means to later do DI it&#039;s related. Got ya.

&gt;&gt; But I have never needed that either, so it is a somewhat constructed argument/problem.

Well, you don&#039;t &quot;need&quot; it. But if you do this, you open up your application for new design possibilities that could change your overall architecture.

But my experience has been that legacy frameworks haven&#039;t considered IoC in the API design which sometimes makes it difficult to use.

However, if you have frameworks that will allow you to utilize this concept through out, it can be very powerful. I can show you some examples later.

Of course, this isn&#039;t as useful on simple applications where you may over engineer your infrastructure code.

&gt;&gt; use the right tools for the right task

!]]></description>
		<content:encoded><![CDATA[<p>&gt;&gt; So injecting a connection from the outside into the command object _is_ dependency injection, and that is exactly what is happening inside the GetCommand method.</p>
<p>I see what you mean. I was focusing on the consumer of the Config factory. Which is NOT using dependency injection. But, yea the sample implementation is using DI. And that&#8217;s your point.</p>
<p>What is confusing is that this pattern is really about the resolver. Only the implementation is using DI. Some test implementation may create a IDbCommand that isn&#8217;t using a connection. You could easily strip this pattern of DI. You could also do all this DI stuff even without the resolver.</p>
<p>So I would still argue that this article is about a locator/resolver and not DI per say. But since you&#8217;re doing it specifically as a means to later do DI it&#8217;s related. Got ya.</p>
<p>&gt;&gt; But I have never needed that either, so it is a somewhat constructed argument/problem.</p>
<p>Well, you don&#8217;t &#8220;need&#8221; it. But if you do this, you open up your application for new design possibilities that could change your overall architecture.</p>
<p>But my experience has been that legacy frameworks haven&#8217;t considered IoC in the API design which sometimes makes it difficult to use.</p>
<p>However, if you have frameworks that will allow you to utilize this concept through out, it can be very powerful. I can show you some examples later.</p>
<p>Of course, this isn&#8217;t as useful on simple applications where you may over engineer your infrastructure code.</p>
<p>&gt;&gt; use the right tools for the right task</p>
<p>!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Alsing</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1147</link>
		<dc:creator><![CDATA[Roger Alsing]]></dc:creator>
		<pubDate>Fri, 08 May 2009 17:54:59 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1147</guid>
		<description><![CDATA[&gt;&gt;I’m just saying, you don’t have anything in there that is doing Dependency Injection. So, the term is misplaced to describe the pattern. It’s IoC but not (necessarily) DI.

That is simply not correct.

The definition of Service location is when a component resolves it&#039;s own dependencies (through the help of the locator).
eg. if the SqlCommand class would ask for it&#039;s own dependencies.


This is not the case here, the SqlCommand class can only by configured through dependency injection.

So injecting a connection from the outside into the command object _is_ dependency injection, and that is exactly what is happening inside the GetCommand method.

The config method &quot;GetCommand&quot; ofcourse uses service location to resolve the objects that will be injected into the subject of the configuration (eg. the command object)

This is exactly how it is implemented in DI frameworks also, the DI framework first needs to resolve the dependencies, and then inject them into the subject.

Regarding one config per app domain:
This is true, but I have yet to see a real world case where you need to be able to have multiple implementations of the same configuration in the same application.
Maybe there is some special case where it is needed, but by all means, use the right tools for the right task.

I&#039;ve used the same argument when I built NAspect, that we support different AOP configurations in the same app domain.
But I have never needed that either, so it is a somewhat constructed argument/problem.]]></description>
		<content:encoded><![CDATA[<p>&gt;&gt;I’m just saying, you don’t have anything in there that is doing Dependency Injection. So, the term is misplaced to describe the pattern. It’s IoC but not (necessarily) DI.</p>
<p>That is simply not correct.</p>
<p>The definition of Service location is when a component resolves it&#8217;s own dependencies (through the help of the locator).<br />
eg. if the SqlCommand class would ask for it&#8217;s own dependencies.</p>
<p>This is not the case here, the SqlCommand class can only by configured through dependency injection.</p>
<p>So injecting a connection from the outside into the command object _is_ dependency injection, and that is exactly what is happening inside the GetCommand method.</p>
<p>The config method &#8220;GetCommand&#8221; ofcourse uses service location to resolve the objects that will be injected into the subject of the configuration (eg. the command object)</p>
<p>This is exactly how it is implemented in DI frameworks also, the DI framework first needs to resolve the dependencies, and then inject them into the subject.</p>
<p>Regarding one config per app domain:<br />
This is true, but I have yet to see a real world case where you need to be able to have multiple implementations of the same configuration in the same application.<br />
Maybe there is some special case where it is needed, but by all means, use the right tools for the right task.</p>
<p>I&#8217;ve used the same argument when I built NAspect, that we support different AOP configurations in the same app domain.<br />
But I have never needed that either, so it is a somewhat constructed argument/problem.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian Markbåge</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1146</link>
		<dc:creator><![CDATA[Sebastian Markbåge]]></dc:creator>
		<pubDate>Fri, 08 May 2009 16:03:37 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1146</guid>
		<description><![CDATA[The first Config object would be instantiated in Main() or Application_Start() or where ever the application is first started. There by eliminating the need for a service locator at all.

For tests I would instantiate a mock or fake Config object in the context where it is needed.]]></description>
		<content:encoded><![CDATA[<p>The first Config object would be instantiated in Main() or Application_Start() or where ever the application is first started. There by eliminating the need for a service locator at all.</p>
<p>For tests I would instantiate a mock or fake Config object in the context where it is needed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sebastian Markbåge</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1145</link>
		<dc:creator><![CDATA[Sebastian Markbåge]]></dc:creator>
		<pubDate>Fri, 08 May 2009 15:52:21 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1145</guid>
		<description><![CDATA[I would still argue that even though your pattern doesn&#039;t necessarily exclude dependency injection. It doesn&#039;t use DI at all. That&#039;s why the title is confusing to me.

In your sample DefaultConfig.GetCommand doesn&#039;t use DI. You could use it there, but you&#039;re currently using a service locator there as well.

I&#039;m not saying that the pattern is wrong or that it&#039;s worse than common DI frameworks.

In fact, this exact pattern is very common in dynamic languages for testing purposed. Every method is overridable so you have a default that is then overridden during tests.

I&#039;m just saying, you don&#039;t have anything in there that is doing Dependency Injection. So, the term is misplaced to describe the pattern. It&#039;s IoC but not (necessarily) DI.

My issue with this pattern is that the application architecture is designed around a default implementation. That could potentially lead the design process to leak across layers.

But, then I have an issue with DI frameworks and global dependency configuration in general but that&#039;s a different story.

You can&#039;t have two different instances of Config in the same app domain for example. That&#039;s makes all your consumers single purpose. I would have Config be a contextualized configuration object that is passed through injection to consumers.]]></description>
		<content:encoded><![CDATA[<p>I would still argue that even though your pattern doesn&#8217;t necessarily exclude dependency injection. It doesn&#8217;t use DI at all. That&#8217;s why the title is confusing to me.</p>
<p>In your sample DefaultConfig.GetCommand doesn&#8217;t use DI. You could use it there, but you&#8217;re currently using a service locator there as well.</p>
<p>I&#8217;m not saying that the pattern is wrong or that it&#8217;s worse than common DI frameworks.</p>
<p>In fact, this exact pattern is very common in dynamic languages for testing purposed. Every method is overridable so you have a default that is then overridden during tests.</p>
<p>I&#8217;m just saying, you don&#8217;t have anything in there that is doing Dependency Injection. So, the term is misplaced to describe the pattern. It&#8217;s IoC but not (necessarily) DI.</p>
<p>My issue with this pattern is that the application architecture is designed around a default implementation. That could potentially lead the design process to leak across layers.</p>
<p>But, then I have an issue with DI frameworks and global dependency configuration in general but that&#8217;s a different story.</p>
<p>You can&#8217;t have two different instances of Config in the same app domain for example. That&#8217;s makes all your consumers single purpose. I would have Config be a contextualized configuration object that is passed through injection to consumers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Alsing</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1144</link>
		<dc:creator><![CDATA[Roger Alsing]]></dc:creator>
		<pubDate>Fri, 08 May 2009 15:23:16 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1144</guid>
		<description><![CDATA[@Jonathan and Andreas:

Yes I&#039;m aware of Autofac, but it actually brings me very little extra compared to the lines of code above.

It does bring some extra object activation features, eg if some object should be singleton or if it should be unique for an entire object graph.

But except for that, I can do pretty much everything with the code above w/o the need for an external framework.

And as the title implies, it is the &quot;simplest form&quot; not the &quot;best&quot; or &quot;most flexible&quot;.]]></description>
		<content:encoded><![CDATA[<p>@Jonathan and Andreas:</p>
<p>Yes I&#8217;m aware of Autofac, but it actually brings me very little extra compared to the lines of code above.</p>
<p>It does bring some extra object activation features, eg if some object should be singleton or if it should be unique for an entire object graph.</p>
<p>But except for that, I can do pretty much everything with the code above w/o the need for an external framework.</p>
<p>And as the title implies, it is the &#8220;simplest form&#8221; not the &#8220;best&#8221; or &#8220;most flexible&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas Håkansson</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1143</link>
		<dc:creator><![CDATA[Andreas Håkansson]]></dc:creator>
		<pubDate>Fri, 08 May 2009 13:24:27 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1143</guid>
		<description><![CDATA[Roger,

For the sake of the argument, you do not need a hard dependency on a single DI framework, you can build your code to use the common service locator

http://www.codeplex.com/CommonServiceLocator

which is a cooperation between MS and the DI community (initiative taken by Ayende).

Also there are plenty of frameworks that doesnt require xml configuration.. for example autofac.. you can even use Modules spread across assemblies if you want

Daniel Cazzulino created Funq http://www.clariusconsulting.net/blogs/kzu/archive/2009/01/30/116274.aspx

Most of them lets you do non xml/magic string resolving]]></description>
		<content:encoded><![CDATA[<p>Roger,</p>
<p>For the sake of the argument, you do not need a hard dependency on a single DI framework, you can build your code to use the common service locator</p>
<p><a href="http://www.codeplex.com/CommonServiceLocator" rel="nofollow">http://www.codeplex.com/CommonServiceLocator</a></p>
<p>which is a cooperation between MS and the DI community (initiative taken by Ayende).</p>
<p>Also there are plenty of frameworks that doesnt require xml configuration.. for example autofac.. you can even use Modules spread across assemblies if you want</p>
<p>Daniel Cazzulino created Funq <a href="http://www.clariusconsulting.net/blogs/kzu/archive/2009/01/30/116274.aspx" rel="nofollow">http://www.clariusconsulting.net/blogs/kzu/archive/2009/01/30/116274.aspx</a></p>
<p>Most of them lets you do non xml/magic string resolving</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1142</link>
		<dc:creator><![CDATA[Jonathan]]></dc:creator>
		<pubDate>Fri, 08 May 2009 12:48:27 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1142</guid>
		<description><![CDATA[A while back, I was in the same boat that you&#039;re.  Doing all of that XML config for DI was scary, and indeed it is.  Further, I didn&#039;t want to use strings all over the place because they didn&#039;t provide me with compile-time safety which made refactoring difficult.  Then I stumbled upon Autofac.  It was designed to address these two exact problems in a very elegant way.  I&#039;ve kicked around a number of other DI frameworks, but this one fit me the best.]]></description>
		<content:encoded><![CDATA[<p>A while back, I was in the same boat that you&#8217;re.  Doing all of that XML config for DI was scary, and indeed it is.  Further, I didn&#8217;t want to use strings all over the place because they didn&#8217;t provide me with compile-time safety which made refactoring difficult.  Then I stumbled upon Autofac.  It was designed to address these two exact problems in a very elegant way.  I&#8217;ve kicked around a number of other DI frameworks, but this one fit me the best.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DotNetShoutout</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1140</link>
		<dc:creator><![CDATA[DotNetShoutout]]></dc:creator>
		<pubDate>Fri, 08 May 2009 09:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1140</guid>
		<description><![CDATA[&lt;strong&gt;The simplest form of configurable Dependency Injection - Roger Alsing...&lt;/strong&gt;

Thank you for submitting this cool story - Trackback from DotNetShoutout...]]></description>
		<content:encoded><![CDATA[<p><strong>The simplest form of configurable Dependency Injection &#8211; Roger Alsing&#8230;</strong></p>
<p>Thank you for submitting this cool story &#8211; Trackback from DotNetShoutout&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://rogeralsing.com/2009/05/07/the-simplest-form-of-configurable-dependency-injection/#comment-1139</link>
		<dc:creator><![CDATA[Mike]]></dc:creator>
		<pubDate>Fri, 08 May 2009 09:27:18 +0000</pubDate>
		<guid isPermaLink="false">http://rogeralsing.com/?p=588#comment-1139</guid>
		<description><![CDATA[If I understand correctly you&#039;re abstracting an IoC container of your choice so that in certain scenarios (unit testing) you can resolve by some simpler means rather than configuring the IoC container.

Personally I&#039;m not too keen on this as it involves writing an abstracting layer (static Config class) and this means more code. Is the issue rather that the IoC container of your choice is a real pain to easily configure for writing unit tests? Maybe consider one that can be easily configured in code like Bloom on codeplex (note: I wrote it) or Autofac.]]></description>
		<content:encoded><![CDATA[<p>If I understand correctly you&#8217;re abstracting an IoC container of your choice so that in certain scenarios (unit testing) you can resolve by some simpler means rather than configuring the IoC container.</p>
<p>Personally I&#8217;m not too keen on this as it involves writing an abstracting layer (static Config class) and this means more code. Is the issue rather that the IoC container of your choice is a real pain to easily configure for writing unit tests? Maybe consider one that can be easily configured in code like Bloom on codeplex (note: I wrote it) or Autofac.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

