<?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: Careful how you inject those dependencies</title>
	<atom:link href="http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/</link>
	<description>Enterprise Development Expert &#38; SOA Specialist</description>
	<lastBuildDate>Fri, 23 Jul 2010 18:21:18 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Darren Oakey</title>
		<link>http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/comment-page-1/#comment-318</link>
		<dc:creator>Darren Oakey</dc:creator>
		<pubDate>Thu, 01 Jun 2006 01:44:26 +0000</pubDate>
		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/286#comment-318</guid>
		<description>I&#039;ve been playing with my own dependency injection engine for a while - my company won&#039;t let me bring in spring or pico, (they don&#039;t allow any code on the premises which they don&#039;t have serious support agreements with the suppliers) and also I find I understand the concepts better if I&#039;ve written the engine myself.

One thing I did immediately is to use generics to minimize the use of strings (and you could wrap a library around an existing dependency injection framework) as well.  This enables much better error handling, and some limited compiler assistance.

I hate the setter paradigm, as it means you have objects floating around that could quite possibly change at any time, so all my objects are constructor initialized. 

What I found was I only wanted to think about objects in a few ways.  

-1- I needed &quot;the/a&quot; something - ie &quot;the&quot; main form, &quot;a&quot; compressor etc etc

] ICompressor compressor = Injector[ICompressor].Get();  
* note - weird syntax is because the blog doesn&#039;t like greater than or less than signs

-2- I needed a &quot;new&quot; object - ie give me a new order record, or a new trade

] ITrade newTrade = Injector[ITrade].New();

-3- I needed ALL the objects implementing a particular interface - for instance all the market visualisation plugins 

] IVisualiser [] visualizers = Injector[IVisualiser].All();

-4- or finally, and the one where I depart most from the traditional, is that I have the idea of a particular action for a particular object - sort of like shell verbs work  - for example, each object can have a control registered to display it, but they follow the object hierarchy, so there is a display for just an &quot;object&quot;, and one for a trade, and one for a particular type of trade.  The program picks the most specific one available..  

] IDisplay theDisplay = Injector[IDisplay].For( thisTrade );

We have automated release systems, dlls released onto network drives, and in our business, even a few minutes outage could have millions of dollars worth of impact... so there is no benefit to us doing the injection from a config file.  Instead, I do the injection from a single &quot;Code&quot; configuration file, which is compiled as the main assembly for the project.  This means that even though the underlying engine is using reflection and strings, there is compile type checking on all objects that are injected - it&#039;s impossible to have the sort of errors to which you are referring.   I find it all works quite nicely, and think it&#039;s a pretty simple paradigm.
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been playing with my own dependency injection engine for a while &#8211; my company won&#8217;t let me bring in spring or pico, (they don&#8217;t allow any code on the premises which they don&#8217;t have serious support agreements with the suppliers) and also I find I understand the concepts better if I&#8217;ve written the engine myself.</p>
<p>One thing I did immediately is to use generics to minimize the use of strings (and you could wrap a library around an existing dependency injection framework) as well.  This enables much better error handling, and some limited compiler assistance.</p>
<p>I hate the setter paradigm, as it means you have objects floating around that could quite possibly change at any time, so all my objects are constructor initialized. </p>
<p>What I found was I only wanted to think about objects in a few ways.  </p>
<p>-1- I needed &#8220;the/a&#8221; something &#8211; ie &#8220;the&#8221; main form, &#8220;a&#8221; compressor etc etc</p>
<p>] ICompressor compressor = Injector[ICompressor].Get();<br />
* note &#8211; weird syntax is because the blog doesn&#8217;t like greater than or less than signs</p>
<p>-2- I needed a &#8220;new&#8221; object &#8211; ie give me a new order record, or a new trade</p>
<p>] ITrade newTrade = Injector[ITrade].New();</p>
<p>-3- I needed ALL the objects implementing a particular interface &#8211; for instance all the market visualisation plugins </p>
<p>] IVisualiser [] visualizers = Injector[IVisualiser].All();</p>
<p>-4- or finally, and the one where I depart most from the traditional, is that I have the idea of a particular action for a particular object &#8211; sort of like shell verbs work  &#8211; for example, each object can have a control registered to display it, but they follow the object hierarchy, so there is a display for just an &#8220;object&#8221;, and one for a trade, and one for a particular type of trade.  The program picks the most specific one available..  </p>
<p>] IDisplay theDisplay = Injector[IDisplay].For( thisTrade );</p>
<p>We have automated release systems, dlls released onto network drives, and in our business, even a few minutes outage could have millions of dollars worth of impact&#8230; so there is no benefit to us doing the injection from a config file.  Instead, I do the injection from a single &#8220;Code&#8221; configuration file, which is compiled as the main assembly for the project.  This means that even though the underlying engine is using reflection and strings, there is compile type checking on all objects that are injected &#8211; it&#8217;s impossible to have the sort of errors to which you are referring.   I find it all works quite nicely, and think it&#8217;s a pretty simple paradigm.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick</title>
		<link>http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/comment-page-1/#comment-317</link>
		<dc:creator>Rick</dc:creator>
		<pubDate>Mon, 22 May 2006 13:45:47 +0000</pubDate>
		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/286#comment-317</guid>
		<description>Indeed. The issue you describe is one that most folks come up against as soon as they start using a mix of scopes (beyond that of plain old singleton).

In the specific case of Spring.NET, you can use the ObjectFactoryCreatingFactoryObject (mmm, gotta to love that name) to remove hardcoded Strings from one&#039;s code... in the case of the OFCFO, one only specifies the lookup name once (which is a good thing). But (and there is always a but ain&#039;t there) this comes at the price of coupling one&#039;s code to Spring (only a simple interface, but still, one doesnlt typically want to go there).

There is another option (in addition to the approach you have taken, and the OFCFO approach) and that is encapulated by the ServiceLocatorFactoryBean. Yes, this class is a Spring Java class, but could easily be ported over to Spring.NET.

There is (yawn) yet another approach, and that is using so-called (I didn&#039;t make these terms up, I just inherited them) Method Injection. This variant is supported by Spring.NET (and Spring) and a host of Java IoC containers. A comment on your blog is not the place to go into this variant, but the following blog entry from Rod Johnson may prove of interest.

http://blog.springframework.com/rod/?p=1

The previous commenter (Jeremy) has a valid point. Spring.NET, StructureMap, whatever :)... I think the main point to take away is that IoC (DI) itself rocks.</description>
		<content:encoded><![CDATA[<p>Indeed. The issue you describe is one that most folks come up against as soon as they start using a mix of scopes (beyond that of plain old singleton).</p>
<p>In the specific case of Spring.NET, you can use the ObjectFactoryCreatingFactoryObject (mmm, gotta to love that name) to remove hardcoded Strings from one&#8217;s code&#8230; in the case of the OFCFO, one only specifies the lookup name once (which is a good thing). But (and there is always a but ain&#8217;t there) this comes at the price of coupling one&#8217;s code to Spring (only a simple interface, but still, one doesnlt typically want to go there).</p>
<p>There is another option (in addition to the approach you have taken, and the OFCFO approach) and that is encapulated by the ServiceLocatorFactoryBean. Yes, this class is a Spring Java class, but could easily be ported over to Spring.NET.</p>
<p>There is (yawn) yet another approach, and that is using so-called (I didn&#8217;t make these terms up, I just inherited them) Method Injection. This variant is supported by Spring.NET (and Spring) and a host of Java IoC containers. A comment on your blog is not the place to go into this variant, but the following blog entry from Rod Johnson may prove of interest.</p>
<p><a href="http://blog.springframework.com/rod/?p=1" rel="nofollow">http://blog.springframework.com/rod/?p=1</a></p>
<p>The previous commenter (Jeremy) has a valid point. Spring.NET, StructureMap, whatever <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> &#8230; I think the main point to take away is that IoC (DI) itself rocks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Miller</title>
		<link>http://www.udidahan.com/2006/05/21/careful-how-you-inject-those-dependencies/comment-page-1/#comment-316</link>
		<dc:creator>Jeremy Miller</dc:creator>
		<pubDate>Mon, 22 May 2006 05:44:39 +0000</pubDate>
		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/286#comment-316</guid>
		<description>Just to be snarky, that issue is why the corresponding code to do Service Location in StructureMap (the .Net 1.1 version anyway) is:

ICustomerForm form = (ICustomerForm)ObjectFactory.GetInstance(typeof(ICustomerForm));

to avoid the string dependency problem that Spring.Net causes.</description>
		<content:encoded><![CDATA[<p>Just to be snarky, that issue is why the corresponding code to do Service Location in StructureMap (the .Net 1.1 version anyway) is:</p>
<p>ICustomerForm form = (ICustomerForm)ObjectFactory.GetInstance(typeof(ICustomerForm));</p>
<p>to avoid the string dependency problem that Spring.Net causes.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
