<p>Is there a down side? I feel almost dependent on it now. Whenever a project gets past a certain size almost feel an allergic reaction to standard patterns and immediately re-wire it with a Dependency Injection framework.</p>

<p>The largest issue I've found is it can be confusing for other developers who are just learning it.</p>

<p>Also, I'd feel much better if it were a part of the language I was using. Though, for Java at least, there are a couple very lightweight libraries which are quite good.</p>

<p>Thoughts? Bad experiences? Or just stop worrying about it?</p>

<hr>

<p>[EDIT] Re: Description of Dependency Injection itself</p>

<p>Sorry for being vague. <a href="http://www.martinfowler.com/articles/injection.html" rel="noreferrer">Martin Fowler</a> probably describes it FAR better than I ever could... no need to waste the effort. </p>

<p>Coincidentally, this confirms one point about it, that it's still not widely practiced and might tend to be a barrier when working with teams if everyone is not up to speed on it. </p>

[{'answer_id': 42713, 'author': 'Artem Tikhomirov', 'author_id': 2313, 'author_profile': 'https://Stackoverflow.com/users/2313', 'pm_score': 1, 'selected': False, 'text': '<p>The only down side I can think of is tiny performance decrease through constant virtual calls :)</p>\n'}, {'answer_id': 42716, 'author': 'Blorgbeard', 'author_id': 369, 'author_profile': 'https://Stackoverflow.com/users/369', 'pm_score': 2, 'selected': False, 'text': '<p>Could you add a link or two to explain what Dependency Injection actually is, for those of us playing along at home? The <a href="http://en.wikipedia.org/wiki/Dependency_Injection" rel="nofollow noreferrer">wikipedia article</a> is entertaining, but not very enlightening.</p>\n'}, {'answer_id': 42717, 'author': 'Kevin Berridge', 'author_id': 4407, 'author_profile': 'https://Stackoverflow.com/users/4407', 'pm_score': 5, 'selected': True, 'text': '<p>I\'ve taken a stab at describing some of the possible downsides in a blog post here: <a href="http://kevin-berridge.blogspot.com/2008/06/ioc-and-di-complexity.html" rel="noreferrer">http://kevin-berridge.blogspot.com/2008/06/ioc-and-di-complexity.html</a></p>\n'}, {'answer_id': 42718, 'author': 'Guy Starbuck', 'author_id': 2194, 'author_profile': 'https://Stackoverflow.com/users/2194', 'pm_score': 2, 'selected': False, 'text': '<p>In my opinion, the major drawbacks are the learning curve (as you point out) and the potential for the added abstraction to make it more difficult to debug (which is really part of the learning curve as well).</p>\n\n<p>To me, DI seems to me to be more appropriate for larger, complex systems -- for small one-off apps, it may result in the app being over-architected, basically, having the architecture take more development time to adhere to than it can ever make up for in the value it provides.</p>\n'}, {'answer_id': 42719, 'author': 'Jakub Šturc', 'author_id': 2361, 'author_profile': 'https://Stackoverflow.com/users/2361', 'pm_score': 2, 'selected': False, 'text': '<p>I am big beleaver in IO however I saw some projects with huge xml configuration files which no one understand. So beware of programming in xml. </p>\n'}, {'answer_id': 42725, 'author': 'morais', 'author_id': 2846, 'author_profile': 'https://Stackoverflow.com/users/2846', 'pm_score': 0, 'selected': False, 'text': '<p>@Blorgbeard: <a href="http://www.martinfowler.com/articles/injection.html" rel="nofollow noreferrer">http://www.martinfowler.com/articles/injection.html</a> is probably one of the best articles on the subject</p>\n'}, {'answer_id': 42738, 'author': 'tgeros', 'author_id': 4458, 'author_profile': 'https://Stackoverflow.com/users/4458', 'pm_score': 2, 'selected': False, 'text': '<p>Just stop worrying about it. It\'s my opinion that in time IoC techniques will be second nature to most developers. I\'m trying to teach devs here at work about it and I find it difficult to get the message across because it feels so unnatural to the way we\'ve always done things.. which just so happened to have been the wrong way. Also, developers both new to IoC and new to a project I find have an even more hard time. They\'re use to using the IDE to follow the trail of dependencies to gain an understanding of how the whole thing "hangs together". That information is often written into arcane XML.</p>\n'}, {'answer_id': 42739, 'author': 'Marcio Aguiar', 'author_id': 4213, 'author_profile': 'https://Stackoverflow.com/users/4213', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n  <p>Also, I\'d feel much better if it were\n  a part of the language I was using.</p>\n</blockquote>\n\n<p>FYI there is a very simple and functional dependecy injection as part of JDK 6. If you need lightweight, straightforward dependency injection, then use it.</p>\n\n<p>Using <a href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html" rel="nofollow noreferrer">ServiceLoader</a> class you can request a service (or many implementations of the service) based on a class:</p>\n\n<pre><code> package dependecyinjection;  \n import java.util.ServiceLoader;  \n\n public abstract class FooService {  \n\n     public static FooService getService() {  \n         ServiceLoader&lt;FooService&gt; loader = ServiceLoader.load(FooService.class);  \n\n         for (FooService service : loader) {  \n             return provider;  \n         }  \n\n         throw new Exception ("No service");  \n     }  \n\n     public abstract int fooOperation();  \n\n }  \n\n package dependecyinjection;  \n public class FooImpl extends FooService {  \n     @Override  \n     public int fooOperation() {  \n         return 2;  \n     }  \n }  \n</code></pre>\n\n<p><strong>How does ServiceLoader defines the service implementations that are returned?</strong></p>\n\n<p>In your project folder create a folder named <em>META-INF/services</em> and create a file named <em>dependencyinjection.FooService</em>. This file contain a line pointing to the service implementation. In that case: dependecyinjection.FooImpl</p>\n\n<p>This is not widely known yet.</p>\n'}, {'answer_id': 4980407, 'author': 'Tergiver', 'author_id': 351385, 'author_profile': 'https://Stackoverflow.com/users/351385', 'pm_score': 3, 'selected': False, 'text': "<p>The problem I have with DI is the same problem I have with COM and with any code that looks something like:</p>\n\n<pre><code>i = GetServiceOrInterfaceOrObject(...)\n</code></pre>\n\n<p>The problem is that such a system cannot be understood from the code. There must be documentation somewhere [else] that defines what service/interface/object can be requested by service/interface/object X. This documention must not only be maintained, but available as easily as the source.</p>\n\n<p>Unless the document is very well written, it's often still not easy to see the relationships between objects. Sometimes relationships are temporal which makes them even harder to discover.</p>\n\n<p>I like the KISS principle, and I'm a strong believer in using the right tool for the job. If the benefit of DI, for a given project, outweighs the need to write comprehensible code, than use it.</p>\n"}]
['https://Stackoverflow.com/questions/42706', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/758/']