﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Mike commented on Rejecting Dependency Injection Inversion</title><description>"CDI/Weld is great because it's part of the Java EE framework as a standard, meaning one less place where configuration is required - complexity goes down."
  
  
For those who do not know: CDI is JSR 299 Contexts and Dependency Injection for the JavaTM  EE platform. 
  
  
When are we going to get a community .NET specification thingy going? It's great the amount of frameworks for DI in .NET, but they are reinventing the wheel all of them. I think it's good to get behind a common spec.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment24</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment24</guid><pubDate>Tue, 26 Jan 2010 12:22:25 GMT</pubDate></item><item><title>Lincoln commented on Rejecting Dependency Injection Inversion</title><description>Java has had a solid dependency injection framework for years with Spring, but now that has been standardized with CDI (JBoss weld is the reference imlementation, and JBoss Seam provides further extension.) I don't think that misuse is the norm, just as other have said, it's possible to misuse anything.
  
  
CDI/Weld is great because it's part of the Java EE framework as a standard, meaning one less place where configuration is required - complexity goes down.
  
  
With great power comes great responsibility.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment23</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment23</guid><pubDate>Mon, 25 Jan 2010 04:09:17 GMT</pubDate></item><item><title>Rog&amp;#233;rio commented on Rejecting Dependency Injection Inversion</title><description>I agree with Jonathan (although I wouldn't "pass loggers down"): DI is often abused, leading to pointless complexity and code...
  
  
Testability shouldn't be an excuse to use DI, since how "testable" your code is depends on the mocking tool you use. In the Java world, we have free (and open source) tools that make writing unit tests for any kind of code easy.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment22</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment22</guid><pubDate>Mon, 25 Jan 2010 01:46:31 GMT</pubDate></item><item><title>Steve Py commented on Rejecting Dependency Injection Inversion</title><description>I've learned to take what Uncle Bob says with a grain of salt. :) As Ayende points out, his argument is  based on a very bad example. 
  
  
For others looking to explore the benefits of IOC Containers, a good starting point is ensuring they understand the fundamental concept of Inversion of Control.
  
  
Start writing code where you are providing dependencies to instances of classes instead of "new"ing them inline, or even using Factories to construct them. This can be by passing them in a constructor, or setting up properties. The key beneffit of IOC as Bradley mentioned, is testability. Once your code is interacting with what it is provided, instead of creating instances of its dependencies, you can substitute those dependencies with Mocks and Stubs to test your code atomically. Provided you also follow good programming fundamentals such as Liskov substitution principle (LSP) it makes your code much easier to modify later on by substituting in new implementations that take advantage of different technologies, etc. (I.e. substituting a logger that logs to file with one that supports event log or DB.)
  
  
 Once this "clicks", then start experimenting with IOC Containers to detect and automatically provide those dependencies. Two good IOC containers to get started with are StructureMap or Autofac. 
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment21</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment21</guid><pubDate>Sat, 23 Jan 2010 00:55:50 GMT</pubDate></item><item><title>Jimmy Zimms commented on Rejecting Dependency Injection Inversion</title><description>Stephen Oakman :
  
  
"I've found that Unity is more the limitation in this sense. It doesn't go as far as I would like (in my opinion) and almost refuse to call it an IoC Container"
  
  
Agreed and technically I'd say it actually ISN'T a container. It's a container-like facade over a factory (which incidentlly is somehting the Unity guys would agree with). For instance, a container "contains" things you put in it. If you don't put something in it you can't get it out of the container. In Unity if you don't put something in it first you still can get it out! This is really because of the architectural mistake of not actually keeping a mapping of registered types on the container but deffering everything to the underlying ObjectBuilder system.
  
  
Don't believe the above? Here's a fun expiriment: Create a UnityContainer and ask for an Object from it. Guess what? You'll get one.
  
  
This is the cause of innumerable unity configuration based bugs than I can tell you. Item not in the container? Throw and exception or return null or something - ANYTHING than make me think it's actually been set up right. [rolls eyes]
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment20</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment20</guid><pubDate>Fri, 22 Jan 2010 23:48:58 GMT</pubDate></item><item><title>Dmitry commented on Rejecting Dependency Injection Inversion</title><description>Uncle Bob did not write that code. It comes from the tutorial on Google Guice, the IOC used in the example.
  
  
[code.google.com/.../](http://code.google.com/docreader/#p=google-guice&amp;s=google-guice&amp;t=Motivation)  
  
This happens in big companies all the time. Just remember the MVC sample applications from Microsoft.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment19</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment19</guid><pubDate>Fri, 22 Jan 2010 17:35:49 GMT</pubDate></item><item><title>Jeremy Gray commented on Rejecting Dependency Injection Inversion</title><description>@Jonathan - but why even pass such objects down all the time in all the places when you can set up an IoC convention once and only once and then have it taken care of everywhere? I haven't instantiated or passed down a dependency in close to two years now, and I was late to the IoC game, in terms of getting it into a client project that is. ;)
  
  
For the record, I also haven't instantiated a factory for dependencies or even written any IoC registration code in just as long, as the automatic registration convention I implemented takes care of that too. I just write new public interfaces that implement my IComponent interface, write new implementations, and then consume them in the ctor arguments of other component implementations. The whole thing gets wired up automatically based on the conventions I established long ago. Ya gotta love low-friction development!
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment18</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment18</guid><pubDate>Fri, 22 Jan 2010 16:29:32 GMT</pubDate></item><item><title>firefly commented on Rejecting Dependency Injection Inversion</title><description>Bradly is right...
  
  
Regarding the registration, not sure about all the other container but both Windsor and StructureMap will allow you to register your entire application with a few lines of codes with a fluent interface :)
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment17</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment17</guid><pubDate>Fri, 22 Jan 2010 14:59:17 GMT</pubDate></item><item><title>Bradley Landis commented on Rejecting Dependency Injection Inversion</title><description>Jonathon,
  
  
I have to disagree.  Probably the single biggest benefit to DI is in testability.  When testing, being able to replace your logging component or database access object is key.
  
  
Thanks,
  
  
Bradley
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment16</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment16</guid><pubDate>Fri, 22 Jan 2010 14:48:05 GMT</pubDate></item><item><title>Jonathan Allen commented on Rejecting Dependency Injection Inversion</title><description>I write applications like that all the time, and I don't see the complexity you are speaking of. I just create the logger and settings objects at the top level and pass them down to whatever components need it. It can be tedious at times to thread everything through, but it isn't the slightest bit complex.
  
  
Dependency Injection only makes sense when you truly don't know what the concrete dependencies are until runtime. For example, generating menus and the pages/forms they link to at run time. For stuff that is never, ever going to change like your logging component or how you access databases, there is just no point to it.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment15</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment15</guid><pubDate>Fri, 22 Jan 2010 14:35:18 GMT</pubDate></item><item><title>Gavin commented on Rejecting Dependency Injection Inversion</title><description>Thanks for your reply, I am so totally going to be using the castle batch registration facility from now on!
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment14</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment14</guid><pubDate>Fri, 22 Jan 2010 14:26:29 GMT</pubDate></item><item><title>Frank Quednau commented on Rejecting Dependency Injection Inversion</title><description>And I forgot to escape the &lt; and &gt;, damn :(
  
  
It says e.g. "s.AddAllTypesOf&lt;IAction&gt;() "
  
and "s.With&lt;HttpHandlerRegistrar&gt;"
  
sorry!
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment13</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment13</guid><pubDate>Fri, 22 Jan 2010 14:18:32 GMT</pubDate></item><item><title>Frank Quednau commented on Rejecting Dependency Injection Inversion</title><description>Greg,
  
another example from StructureMap:
  
Scan(s =&gt;
  
             {
  
               s.AssemblyContainingType
&lt;siteregistry();
  
               s.AddAllTypesOf
&lt;iaction().NameBy(t =&gt;             
  
                  t.Name.Replace("Action",  "").ToLowerInvariant());
  
             });
  
means, register all types implementing IAction with a name that is derived from the type's name with a certain convention. 
  
  
A good IoC may also help you in separating your conventions from your wiring code:
  
Scan(s=&gt;
  
             {
  
               s.AssemblyContainingType
&lt;siteregistry();
  
               s.With
&lt;httphandlerregistrar();
  
             }); 
  
HttpHandlerRegistrar is a convention for finding IHttpHandler implementations and name it with a relative URL provided via attribute. Such conventions can be reused, which can dramatically reduce your wiring code.
&gt;</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment12</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment12</guid><pubDate>Fri, 22 Jan 2010 14:15:13 GMT</pubDate></item><item><title>Suedeuno commented on Rejecting Dependency Injection Inversion</title><description>Jonty, you don't even need that as StructureMap will scan all assemblies with a single line on of code. 
  
  
x.LookForRegistries();
  
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment11</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment11</guid><pubDate>Fri, 22 Jan 2010 14:11:39 GMT</pubDate></item><item><title>Ayende Rahien commented on Rejecting Dependency Injection Inversion</title><description>Gavin,
  
Take a look here: 
[http://ayende.com/Blog/category/451.aspx](http://ayende.com/Blog/category/451.aspx)  
That is just one example of how to implement convention over configuration for a container. You setup the parameters, and then you are pretty much done with it
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment10</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment10</guid><pubDate>Fri, 22 Jan 2010 14:10:00 GMT</pubDate></item><item><title>Gavin commented on Rejecting Dependency Injection Inversion</title><description>Ayende, you mention that we stopped manually mapping between services and their implementation in 2006. Could you please elaborate on what you mean by this. Are you actually talking about manually writing xml config file for a given container ie. Castle Windsor? If so, how else would you do it? I find attributes a little invasive but would use them if I had to. I also struggle to see how you would request instances from a given container without the use of a factory vis a vis auto registration.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment9</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment9</guid><pubDate>Fri, 22 Jan 2010 14:08:34 GMT</pubDate></item><item><title>Eddie commented on Rejecting Dependency Injection Inversion</title><description>Uncle Bob tried using the Straw Man Argument:
  
  
[http://en.wikipedia.org/wiki/Straw_man](http://en.wikipedia.org/wiki/Straw_man)  
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment8</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment8</guid><pubDate>Fri, 22 Jan 2010 14:06:26 GMT</pubDate></item><item><title>Jonty commented on Rejecting Dependency Injection Inversion</title><description>We only use constructor injection and use StructureMap to auto wire it up. All we need is:
  
  
Scan(x =&gt; {
  
    x.Assembly("MyAssembly1");
  
    x.Assembly("MyAssembly2");
  
    x.WithDefaultConventions();
  
});
  
  
DefaultConventions ties up the interface with its concrete class, eg ICustomerService to CustomerService. Then we only need to be specific when the lifecycle of the instance is different.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment7</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment7</guid><pubDate>Fri, 22 Jan 2010 13:22:30 GMT</pubDate></item><item><title>Greg commented on Rejecting Dependency Injection Inversion</title><description>I have to confess, I'm stuck in the "confused by IOC" camp.  I keep hearing IOC veterans talking about how easy it is, how if it's hard that's because you're doing it wrong -- but then they never go on to demonstrate, with substantial code examples, how to do it right.  Where are the good implementations, that use IOC the right way, in nontrivial real-world apps?  A pointer to two or three of those would be worth a hundred blog posts saying "Uncle Bob is wrong".  
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment6</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment6</guid><pubDate>Fri, 22 Jan 2010 11:54:49 GMT</pubDate></item><item><title>Stephen Oakman commented on Rejecting Dependency Injection Inversion</title><description>Thoai,
  
  
I've found that Unity is more the limitation in this sense. It doesn't go as far as I would like (in my opinion) and almost refuse to call it an IoC Container. Using something like windsor enables more of a mindset change as it supports not only auto registration (which is why you are experiencing the pain you are having) but also the lifestyle management and facilities open up so many more possibilities.
  
  
When unity is the only exposure to IoC I've just not seen them 'get' the benefits of IoC and ultimately it ends up being a mess. Of course, ymmv but I would strongly suggest giving something like windsor a go and see what possibilities it opens up.
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment5</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment5</guid><pubDate>Fri, 22 Jan 2010 11:42:15 GMT</pubDate></item><item><title>Bunter commented on Rejecting Dependency Injection Inversion</title><description> Thoại, nobody orders you to put all the IoC setup into single class... Maybe the main drawback sits between the table and the chair?
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment4</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment4</guid><pubDate>Fri, 22 Jan 2010 11:12:00 GMT</pubDate></item><item><title>Ayende Rahien commented on Rejecting Dependency Injection Inversion</title><description>Thoai,
  
They you have a problem in the way you are using IoC, period.
  
Most commonly, I have about 10 lines to setup IoC for an entire project
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment3</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment3</guid><pubDate>Fri, 22 Jan 2010 11:02:30 GMT</pubDate></item><item><title>Thoại Nguyễn commented on Rejecting Dependency Injection Inversion</title><description>Hi Ayende,
  
  
Thank for your post. The case you mentioned above is exactly like my case. I'm using Unity as the IOC library. Since i don't want to make my Service implementation dirty with [Dependency] attribute from Unity, I decided to use Contructor injection. However, following this approach, the bootstrapper becomes a huge class with thousand lines of injection code for service classes. Personally, I think It's really the main drawback when using IOC 
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment2</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment2</guid><pubDate>Fri, 22 Jan 2010 10:47:46 GMT</pubDate></item><item><title>Achim Domma commented on Rejecting Dependency Injection Inversion</title><description>Thanks for this very interesting point of view! I usually really like Uncle Bobs writings and I'm surprised that he mixes up the limitations of concrete implementations in the java world and the limitations of an abstract concept.
  
  
What readings would you recommend to somebody to get started with DI in the .Net world? My feeling is, that there is a lot of information available, which leads you in the wrong direction as their technics are implementation/language dependent. Also there are many DI implementations in .Net and you have to get started with one. But how to choose one if you are not already an DI expert?
  
  
cheers,
  
Achim 
</description><link>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment1</link><guid>http://ayende.com/4372/rejecting-dependency-injection-inversion#comment1</guid><pubDate>Fri, 22 Jan 2010 10:31:46 GMT</pubDate></item></channel></rss>