Dependency Injection Inversion 304
Dependency Injection is all the rage. There are several frameworks that will help you inject dependencies into your system. Some use XML (God help us) to specify those dependencies. Others use simple statements in code. In either case, the goal of these frameworks is to help you create instances without having to resort to new or Factories.
I think these frameworks are great tools. But I also think you should carefully restrict how and where you use them.
Consider, for example, this simple example using Google’s Guice framework.
public class BillingApplication {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new BillingModule());
BillingService billingService = injector.getInstance(BillingService.class);
billingService.processCharge(2034, "Bob");
}
}
My goal is to create an instance of BillingService. To do this, I first get an Injector from Guice. Then I use the injector to get an instance of my BillingService class. What’s so great about this? Well, take a look at the constructor of the BillingService class.
class BillingService {
private CreditCardProcessor processor;
private TransactionLog transactionLog;
@Inject
BillingService(CreditCardProcessor processor, TransactionLog transactionLog) {
this.processor = processor;
this.transactionLog = transactionLog;
}
public void processCharge(int amount, String id) {
boolean approval = processor.approve(amount, id);
transactionLog.log(
String.format("Transaction by %s for %d %s",
id, amount, approvalCode(approval)));
}
private String approvalCode(boolean approval) {
return approval?"approved":"denied";
}
}
Oh ho! The BillingService constructor requires two arguments! A CreditCardProcessor and a TransactionLog. How was the main program able to create an instance of BillingService without those two arguments? That’s the magic of Guice (and of all Dependency Injection frameworks). Guice knows that the BillingService needs those two arguments, and it knows how to create them. Did you see that funky @Inject attribute above the constructor? That’s how it got connected into Guice.
And here’s the magic module that tells Guice how to create the arguments for the BillingService
public class BillingModule extends AbstractModule {
protected void configure() {
bind(TransactionLog.class).to(DatabaseTransactionLog.class);
bind(CreditCardProcessor.class).to(MyCreditCardProcessor.class);
}
}
Clever these Google-folk! The two bind functions tell Guice that whenever we need an instance of a TransactionLog it should use an instance of DatabaseTransactionLog. Whenever it needs a CreditCardProcessor it should use an instance of MyCreditCardProcessor.
Isn’t that cool! Now you don’t have to build factories. You don’t have to use new. You just tell Guice how to map interfaces to implementations, and which constructors to inject those implementations in to, and then call Injector.getInstance(SomeClass.class); and voila! You have your instance automatically constructed for you. Cool.
Well, yes it’s cool. On the other hand, consider this code:
public class BillingApplicationNoGuice {
public static void main(String[] args) {
CreditCardProcessor cp = new MyCreditCardProcessor();
TransactionLog tl = new DatabaseTransactionLog();
BillingService bs = new BillingService(cp, tl);
bs.processCharge(9000, "Bob");
}
}
Why is this worse? It seems to me it’s better.
But Uncle Bob, you’ve violated DIP by creating concrete instances!
True, but you have to mention concrete instances somewhere. main seems like a perfectly good place for that. Indeed, it seems better than hiding the concrete references in BillingModule.
I don’t want a bunch of secret modules with bind calls scattered all around my code. I don’t want to have to hunt for the particular bind call for the Zapple interface when I’m looking at some module. I want to know where all the instances are created.
But Uncle Bob, You’d know where they are because this is a Guice application.
I don’t want to write a Guice application. Guice is a framework, and I don’t want framework code smeared all through my application. I want to keep frameworks nicely decoupled and at arms-length from the main body of my code. I don’t want to have @Inject attributes everywhere and bind calls hidden under rocks.
But Uncle Bob, What if I want to get an instance of BillingService from deep in the bowels of my application? With Guice I can just say injector.getInstance(BillingService.class);.
True, but I don’t want to have createInstance calls scattered all through my code. I don’t want Guice to be poured all over my app. I want my app to be clean, not soaked in Guice.
But Uncle Bob, That means I have to use new or factories, or pass globals around.
You think the injector is not a global? You think BillingService.class is not a global? There will always be globals to deal with. You can’t write systems without them. You just need to manage them nicely.
And, no, I don’t have to use new everywhere, and I don’t need factories. I can do something as simple as:
public class BillingApplicationNoGuice {
public static void main(String[] args) {
CreditCardProcessor cp = new MyCreditCardProcessor();
TransactionLog tl = new DatabaseTransactionLog();
BillingService.instance = new BillingService(cp, tl);
// Deep in the bowels of my system.
BillingService.instance.processCharge(9000, "Bob");
}
}
But Uncle Bob, what if you want to create many instances of BillingService rather than just that one singleton?
Then I’d use a factory, like so:
public class BillingApplication {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new BillingModule());
BillingService.factory = new BillingServiceFactory(injector);
// Deep in the bowels of my code.
BillingService billingService = BillingService.factory.make();
billingService.processCharge(2034, "Bob");
}
}
But Uncle Bob, I thought the whole idea was to avoid factories!
Hardly. After all, Guice is just a big factory. But you didn’t let me finish. Did you notice that I passed the Guice injector into the factory? Here’s the factory implementation.
public class BillingServiceFactory extends AbstractModule {
private Injector injector;
public BillingServiceFactory(Injector injector) {
this.injector = injector;
}
protected void configure() {
bind(TransactionLog.class).to(DatabaseTransactionLog.class);
bind(CreditCardProcessor.class).to(MyCreditCardProcessor.class);
}
public BillingService make() {
return injector.getInstance(BillingService.class);
}
}
I like this because now all the Guice is in one well understood place. I don’t have Guice all over my application. Rather, I’ve got factories that contain the Guice. Guicey factories that keep the Guice from being smeared all through my application.
What’s more, if I wanted to replace Guice with some other DI framework, I know exactly what classes would need to change, and how to change them. So I’ve kept Guice uncoupled from my application.
Indeed, using this form allows me to defer using Guice until I think it’s necessary. I can just build the factories the good old GOF way until the need to externalize dependencies emerges.
But Uncle Bob, don’t you think Dependency Injection is a good thing?
Of course I do. Dependency Injection is just a special case of Dependency Inversion. I think Dependency Inversion is so important that I want to invert the dependencies on Guice! I don’t want lots of concrete Guice dependencies scattered through my code.
BTW, did you notice that I was using Dependency Injection even when I wasn’t using Guice at all? This is nice and simple manual dependency injection. Here’s that code again in case you don’t want to look back:
public class BillingApplicationNoGuice {
public static void main(String[] args) {
CreditCardProcessor cp = new MyCreditCardProcessor();
TransactionLog tl = new DatabaseTransactionLog();
BillingService bs = new BillingService(cp, tl);
bs.processCharge(9000, "Bob");
}
}
Dependency Injection doesn’t require a framework; it just requires that you invert your dependencies and then construct and pass your arguments to deeper layers. Consider, for example, that the following test works just fine in all the cases above. It does not rely on Guice, it only relies on the fact that dependencies were inverted and can be injected into BillingService
public class BillingServiceTest {
private LogSpy log;
@Before
public void setup() {
log = new LogSpy();
}
@Test
public void approval() throws Exception {
BillingService bs = new BillingService(new Approver(), log);
bs.processCharge(9000, "Bob");
assertEquals("Transaction by Bob for 9000 approved", log.getLogged());
}
@Test
public void denial() throws Exception {
BillingService bs = new BillingService(new Denier(), log);
bs.processCharge(9000, "Bob");
assertEquals("Transaction by Bob for 9000 denied", log.getLogged());
}
}
class Approver implements CreditCardProcessor {
public boolean approve(int amount, String id) {
return true;
}
}
class Denier implements CreditCardProcessor {
public boolean approve(int amount, String id) {
return false;
}
}
class LogSpy implements TransactionLog {
private String logged;
public void log(String s) {
logged = s;
}
public String getLogged() {
return logged;
}
}
Also notice that I rolled my own Test Doubles (we used to call them mocks, but we’re not allowed to anymore.) It would have been tragic to use a mocking framework for such a simple set of tests.
Most of the time the best kind of Dependency Injection to use, is the manual kind. Externalized dependency injection of the kind that Guice provides is appropriate for those classes that you know will be extension points for your system.
But for classes that aren’t obvious extension points, you will simply know the concrete type you need, and can create it at a relatively high level and inject it down as an interface to the lower levels. If, one day, you find that you need to externalize that dependency, it’ll be easy because you’ve already inverted and injected it.

Of course Guice looks like overkill for and example with 2 dependencies and a single scope/lifetime. What happens if some of the dependencies need be created per HttpRequest, some are created new each time and some are singletons? Are you going to write a factory for each scope?
Fortunately, I hardly consider this post controversial. In my book, DI is simply a set of patterns and principles that describe how we can write loosely coupled code. These include the GoF principle of programming to interfaces, as well as patterns such as Constructor Injection.
DI simply describes how you organize classes and turn their dependencies into invariants.
How you decide to wire up those dependencies in the end are much less important. You can use Poor Man’s DI (as you show in one of your Main examples), or you can use a DI Container (in .NET, most DI Containers don’t require you to put attributes or other explicit things in the code to work).
The Hollywood Principle is very applicable to DI: Don’t call the DI Container, it’ll call you.
The best approach is to let the container wire up the desired object graph in the application’s entry point and then get out of the way. I call this place the Composition Root.
The idea is to keep the application code completely Container-agnostic.
In summary, I agree :)
Yeah – my view on IOC/DI for years has been that using a DI framework is something I consider down the line, but my starting point is wiring by hand.
BTW, I would not consider creating concrete instances to be a violation of DIP (not that I would care about it violating some rule anyway if I thought that it was the right solution) – not when the instances are then just being provided to the class that will use them.
Like the previous commentator, I do find DI frameworks useful for things like lifecycle management (even then their not essential), and for the fact that they can remove the need for some boiler-plate wiring code.
Personally, I prefer Pico to Guice – why on earth did they think @inject was a good idea when a class only has one constructor?
Can I suggest changing the example code to Injector.getInstance(SomeInterface.class) in your post? I have had to spend hours with some people explaining how DI gets you from an interface to an implementation, and the process seemed easier when I clearly separated what was interfaces and implementations in my examples.
Personally, I really like the annotations used by Spring. I can declare a class to be a service by annotating the class with a @Service annotation. The service gets injected in a similar manner to what you show with Guice.
The only explicit configuration I need to do outside of my services is where I have multiple service implementations around, which I wouldn’t usually have. I really like this because it mostly does away with the need of having wiring of dependencies in a separate entity – main methods or xml files. All configuration is local to the service or the consumer of the service – and it is possible to make tooling that lets you move from one to the other.
I like how you managed to put all the Guice stuff inside a factory. I do expect, though, that in a real application, with multiple factories for different object, it would become a bit messy. But it’s concentrated mess.
I have to ask – when do you consider moving from hand written test doubles to a framework? And where in a TDD process would you decide that?
Gil Zilberfeld
Typemock
The only place that should have reference to the container should be the bootstrapping code (main in your case). I would not use any container that requires otherwise.
Yes, an injector is a factory, but it will usually only be called once per application. The rest is wired and has no dependency to the injector. No serious Guice user will use the injector directly in order to obtain some object.
The problem is not the factory or the new operator but the static dependency. You should know that as a TDD friend.
And, yes , you can’t get rid of globals completely, but you can get rid of many dependencies to them. Stating that one should give up on removing them, because you can’t get rid of them completely is IMHO very questionable.
But Uncle Bob, what if CreditCardProcessor has two dependencies, and DatabaseTransactionLog has two dependencies, and each of those has two dependencies… (Remember the Faberge Shampoo commercial?)
You suggest we can create instances at a relatively high level and inject them down as an interfaces to the lower levels, but I contend that as the graph gets larger that quickly becomes unwieldy.
The point of Guice (and similar tools) is not to avoid factories, instead it fills the role of one-big-factory so you don’t have to. From my perspective, Guice exactly supports the role/spirit/purpose of GOF factories, just with less ceremony.
Hi Uncle Bob,
As much as I appreciate your thoroughness, wasn’t this post a bit too long? :)
To the point – The way you’re using DI here really is quote awful – just like you say yourself. DI should be used more carefully and with component oriented programming in mind.
One of the most important principles is to decouple the application from the specific DI container. Your classes need to be “DI free” in that no special attributes are present and no direct calls are made to DI container instances.
Ideally IMHO, the container really should only be used only on bootstrapping to initially weave the components together.
You can have both the flexibility of DI with only a minimal impact on code readability and maintain independence from tightly coupled containers and their meta data.
Uncle Bob, thanks for the wonderful post. I don’t always agree with what you have to say (and that’s a good thing) but this one I thin hit the nail succinctly and elegantly on the head.
Thanks for the post Uncle Bob. While I appreciate your desire for simplicity by minimizing your reliance on DI and mocking frameworks, the example set forth here falls short in highlighting either the real benefits or faults of DI containers (I know, you said you hate the name container, but that’s what everyone calls them so if you are going to say fake vs. mock because of that then …).
One issue in this example is in your presumption of how DI frameworks are generally used. I think it’s important to draw a distinction between Dependency Injection and the Service Locator pattern here. Dependency Injection is the process of separating the concerns of acquiring dependencies from an object, while the Service Locator pattern merely provides a layer of indirection for acquiring dependencies (not necessarily performing any injection on the object being obtained). While I’ve found that newcomers do tend to gravitate toward using containers directly as a service locator, the container should generally only ever be referenced in an application’s bootstrapping related components, or at most in module or application level controllers. An application can generally be designed to have all dependencies resolved through the container with minimal infrastructure coupling to the actual DI framework.
Another issue is that your example only demonstrates dependency injection with a two-level object graft. It fails to highlight the strengths of a DI container with more typical scenarios, or the weaknesses of the manual approach you advocated.
For most needs, I now use Scala’s “self types” and traits to accomplish the goals of DI/IoC using Scala code itself, rather than a separate framework:
http://programming-scala.labs.oreilly.com/ch13.html#DependencyInjectionInScala
In my case, the point where I started using Guice the first time was when it was time to implement a request scope in the application. Implementing scopes with hand-written factories would have been very complicated, but with Guice it was easy. At that point the project had about 2000 SLOC production code (77 .java files) and 3000 SLOC test code. Creating a custom request scope (and the application’s subsystem which is based on scopes), annotating existing classes with @Inject and writing the Guice modules took in total 4 hours.
This experience showed me that manual DI can get you quite far, and then when the dependencies get complex enough or you need some other features of a DI container, adding a DI container to the project is quick and easy.
True, unless you need to inject instances which are created by some other system. I’ve had one situation where the Injector had to be used directly: some Java objects are deserialized from a database and they need to have some runtime dependencies injected. This means that when the objects are deserialized, they are passed to Injector.injectMembers() – that is done by a tiny class that does nothing else than hold the injector and is completely decoupled from the rest of the application.
And even in that case the use of Injector could have been avoided by hard coding that which class requires which dependency (there are only one or two classes which require this special handling), although using the Injector keeps the system more decoupled (if the injectMembers() call proves to be slow, then hard coding it is a potential performance optimization).
You can have multiple injectors in the same JVM, even within the same application, and they will not know anything about each other – if the application is structured well, they will not even be able to get access to each other even if they tried. When an injector is not anymore used, it will be garbage collected from the memory.
The injector is not a global variable, unlike the horrible mutable static BillingService.instance/factory field. (Such fields are usually needed only temporarily, when incrementally refactoring a large Service Locator based application to use DI.)
Like others have said, a DI example with just 3 classes can not be used to discuss the pros and cons of manual DI vs. container-assisted DI. You’ll need an example (a real application) with tens or hundreds of classes to discuss the benefits of container-assisted DI.
Yes, it is possible to do DI by hand. And in small applications, the amount of code required to construct objects is comparable. But for multiple-developer applications, you’ll write less code if you use a framework.
Before you abandon Guice, consider a few things that your post has overlooked…
Lazy initialization via Providers. Wherever you want you can defer initialization of a dependency by injecting a Provider rather than a Foo. Doing this with by-hand DI is possible, but your code size will blow up significantly. Particularly since you’ll need to rewrite every path that uses a given dependency.
HTTP sessions and request scoping. Without a framework, working with session objects is ugly. You need to think about concurrency, mapping keys to values, and casting. Guice takes care of all of this for you with just an annotation: @SessionScoped.
Modularity. You can reuse Guice modules across applications. The module is a unit of encapsulation, and no single piece of code needs to know the implementation classes of multiple modules.
Holy shit, Bob, is this what you see actual programmers doing? They’re inverting the dependencies, all right, but apparently for fun and not for profit.
As I understand the DIP, we benefit from pushing the decisions about which implementations to choose for our interfaces up towards the entry point. At the entry point, we make as many of those decisions as possible, creating a graph of loosely-coupled objects that request services primarily through abstractions. Then we invoke go() and magic happens. As I teach design, our goal is to wrangle all those pesky “new” calls into a single place, so we no longer need crazy things like Singletons and the only Factories we need are Abstract Factories, which have a real purpose, rather than just confusing people learning how to depend on more abstractions.
I might just have to riff on this later. Thanks.
Interesting. Your point is that by overusing DI frameworks, we are creating an application that has a heavy dependency on them, which we need to invert.
I like the idea of using the factory to encapsulate the framework, very interesting post.
Yes, Guice is framework…yet an elegant and rigorous Dependency Injector implementor. The problem is that too many people confuses the dependency injection paradigm with the framework of the moment, too many people thinks that Pico, Guice, Spring and DI are the same thing… Manual DI is perfect for small projects!
An injector is automation tool for wiring dependencies and in the case of Guice this is done rigorously following the DI concepts (key, scope,... etc); I see no problem with this approach.
- “I don’t want a bunch of secret modules with bind calls scattered all around my code” There are no secrets, simply there is a “declarative way” wiring implementor without using an external language like xml and having a compile time check capability. Probably only in the “main” method the dependency are “hidden”, in the rest of the code the Dependency Inversion Principle predominates. Said that , I will add that the Guice module code is part of the production code so everybody must know in which way the dependencies are wired (in the same way if the wiring was done by hand in a “application factory”).
- “I don’t want to write a Guice application.” Nor do I, who said that having some annotations (dependency keys) on my code that means that is automatically a Guice Application? (I have many other type of annotations on my code…)
- You think the injector is not a global? Yes I think so, at least not in the evil sense. Remember that we are not speaking about globals on business logic… Scope is an VERY IMPORTANT dependency injection concept that Guice, Spring etc implements. (also you can have different injectors in the same application if you prefer).
- “After all, Guice is just a big factory” I think that this definition is too simplistic, it doesn’t address important DI concepts like keys, scope, lifecycle … I would add also that it is “boiler plate code”-less automatic factory.
-“if I wanted to replace Guice with some other DI framework” No problem, the classes are written in DI style mode declaring dependencies following DIP, Guice doesn’t matters.
I strongly agree that speaking of DI doesn’t mean speaking of a particular framework but everybody must study well the DI own concepts! Starting to write DI by hand is a good starting point for understanding its concepts and some constructs used by Guice (like Provider) are very useful.
The problem is that most JEE applications have their entry-point defined in the web.xml as servlet/filter. From that point you need a factory to retrieve your dependencies. Even if you use some web framework, you still need a factory (or DI-plugin) to get to your dependencies.
And once you need a factory its almost always easier to use a DI-framework. Because all DI-frameworks have a factory build-in, but can also wire the dependencies for you.
The other big advantage of using a DI-framework is that everybody in larger projects will manage their classes in a similair way. This will help maintainability and extendibility.
But I have to agree on the concept DI being confused with DI-frameworks. I’ve seen a lot of times, people using something like Spring or Guice without really understanding the pattern. This is very bad! I, myself, give Spring courses to collegues, and the first thing I teach them is to write their own “Spring”, their own dependency injection code.
First I present them with some unmanaged code and ask them to write a unit-test. Of course this can’t be done because the service itself creates the layers below. They don’t have a way to replace the dependencies, so no way to use stubs/mocks. After that I show them how to write/use a factory, and then I show them how to use the DI-pattern… And finally we use Spring as a generic DI-solution.
- “I don’t want a bunch of secret modules with bind calls scattered all around my code.”
So don’t scatter them. Put them all one place.
- “I don’t want lots of concrete Guice dependencies scattered through my code.”
I agree with this. I first learned about DI containers in the .NET world and when I saw that Guice requires constructors to be annotated I was a bit disappointed.
Some very good points. There seems to be a widespread overuse of DI frameworks to solve every problem. I am beginning to feel that we need a language solution to eliminate the problem at the source instead of trying to cure it with frameworks. Anytime I see frameworks abounding, I think language evolution.
I think I’m going to have to side with J.B. on this one – I don’t believe that this advice is really leading to a big payoff for most developers.
In particular, there’s the ‘propagation of dependencies’ antipattern (http://www.picocontainer.org/propagating-dependency-antipattern.html), which you don’t seem to show any solutions to. And I’m concerned that the non-DI container steps you would probably take to avoid that antipattern would actually be more complicated than just using a lightweight DI library. (Passing around a context object that contains common dependencies being a common approach).
Dependence on a specific DI framework – agreed, that’s not a good thing. Should we preemptively spend developer time just in case we may need to switch out our DI implementation? I don’t think so – not if I was paying for the project. I don’t abstract away from the fact that I’m using a particular GUI toolkit (or JS toolkit, etc) these days – sure I might change it, but odds are I wont, and the cost of that abstraction is very real. Truth be told, all the projects I’ve been on have just stuck with what they were using for DI stuff, and the cost to change an @Inject annotation to a synonymous approach is near-zero.
Though I think I agree with the core of your sentiments – if our POJO’s were free of DI specifics, and just loosely coupled via interface dependencies (which are resolved clearly at the top level), then that’s a good place to be. And for small projects, manual DI is almost certainly preferable.
Dean’s suggestion of the Scala way to do it is interesting – use language level features that don’t really bind you in any way, and still allow alternate implementations to be used in a test environment. But truth be told, I’ve found that guice still reads better for me (right now) in this role.
Just a fyi.. The @Inject annotation along with a bunch of other DI related annotations have been standardized in javaee 6 (JSR-299 and JSR-330). So once we upgrade to javaee 6 (or use a DI container like Spring 3.0 which implements JSR-330) we will not have framework specific annotations (and imports) scattered all over the place.
Thanks for the nice article; it raises some very interesting questions. I think that the key point is that we are not interested in the DI frameworks per se, but we should be interested in the basic notion of DI: objects shouldn’t know about their surroundings, and an external entity should be responsible for instantiating the objects and wiring them together. We can do this manually, but as we do this over, a pattern will eventually emerge and we will end up with some form of a framework to help us do DI. If we reach this point, then I think that is better to reuse a standard DI framework rather than rolling one of our own. At the very least, the third-party framework (be it Guice or Spring) will be familiar to more developers, and it will have more experienced developers supporting it.
One key area where flexible DI frameworks shine is where we need to have different object-wirings for different situations. For example, when running unit tests, or on a mobile device, or so on. In each of these cases, we might want different implementations to be plugged in to address the specific problem at hand, and a DI framework would provide more flexibility in doing this.
Yes, this tiny example is worthless. I use DI extensively in Tapestry and it solves a lot of problems that Uncle Bob is glossing over.
First of all, late binding is very important when building a framework that must allow for extensions by third party libraries or by specific applications.
A DI container makes thread-safe just-in-time instantiation possible in a way that is not feasable for an ad-hoc collection of objects. Further, Tapestry IoC adds other features, such as service decoration & advice wherein different concerns of a service can be layered together.
My experience is that on any large system, DI is quite necessary (in Java, at least … higher level languages like Clojure have less need, because the language itself provides the benefits of a DI container).
I think we all (more or less) agree that most systems need some kind of dependency injection mechanism, or else they become a total mess.
I, however, still stick to the “xml-god-help-us”-solution, as this is the only way to ensure that the implementation classes are independent of the dependency injection framework (well, most are, at least).
I haven’t much experience with the annotation-based systems, but as far as I can tell they seem to make it very difficult to exchange dependency implementation to use for a specific test case. If find it very similar to early j2ee dependency resource lookups, which is nearly the opposite of dependency injection. The syntax is a whole lot better, though.
For systems where responsiveness or consistency in various scenarios is extremely important (and probably a lot of other cases too), you get quite some amount of tests simulating various interleavings of concurrent actions, different kinds of integration-point breakdowns etc where a specific ‘bean’ or two must be replaced in each test case in order to simulate the breakdown. Re-binding implementation classes can easily wreck the other tests in the test suite or make the execution order significant. Seems to me that the simple solution is to not have anything magically @inject’ed.
Also: dependency injection framework fashion is extremely short lived. You might want to switch.
I took some time to describe how I usually teach Spring/Guice.
Like I commented before, its based on the fact that the DI-pattern is much much more important then the actual framework of choice.
You have to understand why you are using a certain pattern/framework, what problem are you in fact trying to tackle or avoid? That is the single most important thing.
You can read my tutorial/write-up here: http://www.redcode.nl/blog/2010/01/dependency-injection-dissection
Uncle Bob, I noticed in a comment elsewhere that you thought it was funny that people were saying your example was too simple when it was straight from the Guice tutorial. There are a couple of issues with that. The Guice tutorial, as a basic introduction to how Guice is used, is naturally going to be simple. The problem with you using that example to say “look, you don’t need a DI framework!” is that Guice is considerably more powerful than the example suggests and scales very well with increasing size and needs of a system (scopes, etc.) where DI by hand does not (it requires explicit wiring of every object your system needs and provides nothing in terms of scoping, delayed instantiation, etc). In other words: in a tiny example, DI by hand looks like a perfectly acceptable solution while Guice looks unnecessary (though even in such a tiny example it doesn’t require more code than doing it by hand)... there’s a strong bias toward the frameworkless code. In a real system that will likely have considerably more dependencies and more complex dependency graphs, a framework will shine by making your code simpler and more focused and overall reducing the amount of code you have to write.
I also get the feeling that part of your motivation for this post is seeing code where a DI framework has been misused, such as injecting the Injector (where it isn’t truely needed) or, god forbid, using a static reference to it all over the place as a Service Locator. In that case I would suggest that the solution is not static references to factories or DI by hand but proper use of the framework. I do agree with you that using some kind of DI is the most important thing and I think that someone who doesn’t yet have a grasp on DI should understand DI by hand before using a framework. However, I’d prefer to see you encourage understanding and proper use of DI frameworks rather than suggesting they are largely unnecessary, as they DO provide significant benefits.
When I read this post, I made it mandatory reading for all of my employees. Having use an IoC container for 5 years now, I have recognized the pendulum swing to abuse it by lying to ourselves by believing that is is not a global and that it in itself is not a dependency.
Late last year, I made an architectural move across the company to officially decouple ourselves from our IoC container (StructureMap). there were too many code files throughout the application calling it’s API directly.
We have now (in some projects) isolated it to a single startup project. These projects configure the specific factories we need as well as wire in extensibility points.
I now consider it just as heinous a dependency as NHibernate or the UI toolkit in play. Our core project (the one with the most code) should not have anything to do with concrete dependencies.
Thanks for the good post.
BillingModule and BillingServiceFactory both extend AbstractModule and do the same binding. Is this necessary to make things work? To me this seems a violation of SRP.
Ok, so you have the “we need an abstraction layer, just in case we want to replace X” argument. Have anyone ever heard this actually being followed up a year later by; “good thing we created that abstraction layer, now we can change X for Y”??
I think the key to this post was “I think these frameworks are great tools. But I also think you should carefully restrict how and where you use them.”
I personally find they help me think clearly on how to design my modules. I have my own factory based framework, and yes, I prefer XML configuration, simply because of the added behavioral attributes and the fact that they save me from any specific code tags such as @Inject.
I think this post is probably aimed more at Google’s Guice framework and less at DI in general.
Here is an extension of this post with my opinion added.
How about use of generics as a DI. No framework required.
http://seermindflow.blogspot.com/2009/07/c-generics-free-but-ugly-dependency.html
@SeeR: The problem is that you are still doing dependency lookup instead of dependency injection. Using XML for configuration setup is not elegant, but at least it keeps configuring the services separate from the application logic. And IDEs provide the same level of coding support as they do for java these days, so it is in fact not more error prone anymore.
The key to easily testable classes is to never mix configuration/setup with use. That is what this blog article is all about, as far as I can tell. If you need references to the DI framework inside the code, you are not keeping these apart. The result is easily a messy web of dependencies where it is not easy (/possible) to change any relationships for simple tests or for future program modifications.
If you do dependency resolution in java code, you need to keep a strong focus on you coding style to prevent configuration code from sneaking into the init-validation or business logic code.
The reason I still stick to XML is that it is not a programming language, making such mistakes impossible. That way you can always create code such as in this blog article, knowing that no service will ever try to “request” any “service” from the “environment” while it is running. The dependencies are injected before you run any program logic.
Okay, sometimes framework- or infrastructure code do need to request other stuff at runtime, but since it requires additional effort to do this, it will be the exception, not the norm.
Why are people so afraid of annotations ? i.e. @Inject
Although in Guice’s case, I would prefer that Guice specific annotations be shipped as a separate jar dependency (from framework code).
Off course I mean DRY instead of SRP. Sorry about that.
Your solution seems not more decoupled than using Guice from outside the factory: if you need to change the DI framework (which is much more improbable than the need to change a component implementation) you will need to change every single factory.
Having an @Inject annotation is not coupling! If you remove the framework, you dont need to remove the annotation.
Also, for your simple example, wiring by hand is a perfect choice. Now, if you have lots of objects with different lifecycles and instantiation policies, you will have a lot of code just to tackle this. I think this is waht you mean with “externalized dependency injection of the kind that Guice provides is appropriate for those classes that you know will be extension points for your system.”, but I would say not only extension points, but also expesive objects that require some lifecycle attention (Hibernate Sessions, Http Sessions, Files, Threads, Connections and so on)
Why not enable feed (RSS) on you blog. It would be nice.
Greetings!
I generally agree with your posts, but not on this one.
MM already mentioned 2 of the assumptions/generalizations taken on this post:
—-—-—-—-—-
- “I don’t want a bunch of secret modules with bind calls scattered all around my code.”
So don’t scatter them. Put them all one place.
- “I don’t want lots of concrete Guice dependencies scattered through my code.”
I agree with this. I first learned about DI containers in the .NET world and when I saw that Guice requires constructors to be annotated I was a bit disappointed.
—-—-—-
In my case I’ve been using StructureMap in .net, and I don’t need any attributes/annotations on the classes. Pretty much all the dependencies are configured in a single place, so there is no issue involved with that.
Only a single time I had a situation where I needed to get an instance from elsewhere in the code. Although I did made a factory to make more explicit the code into the DI container, I don’t think going without is an issue to change containers – take out the reference to the DI container, compile & u get the 0-3 lines of code that referenced it (besides the one in the main registration code of course).
I think this post is a little misleading and leaves out the most importend things about IoC. Reading Ayende’s answer to it should make this clear:
http://ayende.com/Blog/archive/2010/01/22/rejecting-dependency-injection-inversion.aspx
I posted my response here but the short answer is: it’s about knowing what you are getting into before you start, and the costs you may incur for your decisions when you start.
I have two major concerns with this post. First. To say that “the goal of these frameworks is to help you create instances without having to resort to new or Factories”, in my opinion, is not at all what dependency injection is about at all. Dependency injection is about, as its name suggests, removing dependencies from your code, decoupling your code, making it more maintainable, and TESTABLE, among other things. The second concern i had was your examples didn’t show why someone would ever use DI. As you stated “My goal is to create an instance of BillingService.” While i agree that you shouldn’t use something just because its cool or everyone is talking about it, or without reason, I just really feel like your example missed the point.
And i wasn’t sure why you were suggesting to use instances or factories?
BillingService.factory = new BillingServiceFactory(injector);
??
The goal is NOT to stop or reduce using new (although it is a side effect of the pattern but not the purpose), and you dont have to use singletons or factories, which i extremely dislike that solution because you are changing the way you design/implement your classes because you use a IOC container, which i think is bad. Not only that but are you really going to make a factory for each class that you want to use DI with? no. The point is to reduce dependencies between concrete classes and program to an interface. So if you dont want Guice all over your code, which i wouldn’t want either because that creates a dependency which is the opposite of what we are trying to do, so what i would do is create a wrapper for Guice that way the application would not depend on that framework and it can be swapped out with any other framework. Now you dont have factories, instances everywhere and you are not tied to a DI framework.
Brilliant post! It created enough of a stir for people to post replies on their blogs leading to valuable insight into various frameworks. Now my DI framework usage is clean, simple and does wonders. Thanks, it really made my day!
After having re-read this post carefully, I think this particular piece of guidance is redundant in .NET.
Not my experience at all. I’ve gone full circle in first not buying into the DI hype and doing everything manually much like you describe, to using Guice as an important part of our architecture. For a long time I thought DI was an example of YAGNI, and I still feel this way when looking at e.g. Spring’s XML configuration, but since adopting Guice, our code got a lot cleaner and easier to configure.
Manually constructing object graphs like you suggest here works fine for small-ish projects but easily gets out of hand in larger ones, particularly if such projects are broken up in multiple projects/ modules/ libraries. Modules provide an excellent mechanism to hide complexities of how such libraries are composed. You could achieve the same by providing builders and such, but then you’d be handwriting what a DI framework already provides. Also, @ImplementedBy and lazy binding provide an excellent way of reducing dumb setup code; in my experience, an composition of a module system uses defaults maybe 70 or 80 % of the time, so your bootstrapping code only has to configure composition for a relatively small number of cases.
> There will always be globals to deal with. You can’t write systems without them
I don’t agree with that. In fact, I am working on a system right now that has no globals to speak of. It requires discipline because it is often easier to rely on globals, but over the years I’ve learned – as many in our industry – that relying on global behavior almost always backfires, and like it is worth the extra effort to think your abstractions through, it is worth the effort of trying to keep the globals down.
> Ok, so you have the “we need an abstraction layer, just in case we want to replace X” argument. Have anyone ever heard this actually being followed up a year later by; “good thing we created that abstraction layer, now we can change X for Y”??
At my new digs (Jive Software), this exact capabity enables us to satisfy unique customer requirements on essentially every install. All the DAOs, managers, etc. are DI injected (currently based on Spring 2.5, would personally prefer @Inject style, we’ll see how long it takes to encourage the other developers in this direction :-), with an ability to install a “plugin” that overrides the default injected resources for any or all of the standard implementations. This is critically important in at least a couple of important use cases:
In a COTS world, anyone who thinks they know the only abstraction points where a customer might want to change things is pretty naive.
I thought you were being crazy until I read through half-way, and then I realised I had the same problem using IoC containers, they were all-over the place.
Good lesson, thanks!
Uncle Bob,
You should take a closer look at Guice and DI in general.
1) In a typical Guice application, you only use Injector in one place—at your applications entry point. Using Injector elsewhere is equivalent to using reflection. Injector is like ClassLoader, another class I hope you don’t use everywhere.
2) To answer your question, no, the injector is not global, nor is the binding to BillingService.class. See private modules. You can easily bind BillingService to different implementations in different parts of your app.
3) You suggested that “TransactionLog tl = new DatabaseTransactionLog()” is preferable to “bind(TransactionLog.class).to(DatabaseTransactionLog.class)”. What happens when you need to inject TransactionLog into a 2nd constructor? You have to type “TransactionLog tl = new DatabaseTransactionLog()” again. With Guice, you do nothing. What happens when you use TransactionLog in 100 places? You type “TransactionLog tl = new DatabaseTransactionLog()” 100 times in 100 different factories. With Guice, you only write one bind statement. Your approach scales O(N). Guice scales O(1). Perhaps you didn’t realize it because N=1 in your example.
Further, if TransactionLog is a concrete injectable class to begin with, you don’t even need a bind() statement. If you decide to replace it with an interface later, you can do so without touching the 100 injection points. Can you do that with your approach?
4) If you don’t use javax.inject.Inject in your code simply because you don’t “want framework code smeared all through [your] application,” you’re making a pretty painful tradeoff.
5) Static fields are notoriously bad for unit testing. We walk you through examples of why in just about all of our Guice videos.
Bob
Hah,that was really funny. I even ordered an essay paper on it.These online essay writers made an excellent essay for me.
I’ve never really used a dependency injection framework in a project for exactly the reasons mentioned. I’ve experimented with a few frameworks and most of them (if not all of them), by their design or by my mistake, added some level of noise and misdirection to the code.
Just didn’t seem worth it, the additional noise.
Really glad this was posted as I wondered whether I was really doing DI even though it felt like it.
Ok some people will argue I am still not doing DI properly, and maybe a situation will arise when I’ll reach for a framework, sure ok I’m easy… but all my code is testable and it’s obvious where and why concrete classes are created; don’t need a framework.
Your point seems to be that you should not use dependency inversion frameworks to make simplistic samples like the one above. A good frame work support many other things like aspects, and transaction handling (to name just two). I want to see how you refactor your code to support that.
—Omar
Hah,that was really funny. I even ordered an essay paper on it.These online essay writers made an excellent essay for me.
welcome to http://www.uggboots4buy.com/ l,will have a unexpection.
Very quietly I take my leave.To seek a dream in http://www.edhardy-buy.com/ starlight.
Living without an aim is like sailing without a compass. with a new http://www.handbags4buy.com/ idea is a crank until the idea succeeds.
all products are high quality but low price,welcome to http://www.uggjordanghd.com/.
>Very nice art, thank you for this site!
Very nice art, thank you for this site!
Thanks for the code. I’ve never tried this stuff before and wonder if it can even be done. WIll give it a shot tonight, a long read but surely worth it. Thanks.
OK, just have a free try!!
It’s sometimes easier to see a problem with a framework clearly when you step back and create an example like this. When you’re in the thick of it your brain can trick you into thinking that there’s only one way at the problem.
I like that the high-level modules do not depend on low-level modules. Both should depend on abstractions. This is one of the principles of dependency injection framework I am raving.
Mosst high level modules are extremely independent of themselves. Injection framework insures that this process is seamlessly taken care of.
Mosst high level modules are extremely independent of themselves. Injection framework insures that this process is seamlessly taken care of.
Your point seems to be that you should not use dependency inversion frameworks to make simplistic samples like the one above. A good frame work support many other things like aspects, and transaction handling (to name just two). I want to see how you refactor your code to support that.
When you’re in the thick of it your brain can trick you into thinking that there’s only one way at the problem.
When you’re in the thick of it your brain can trick you into thinking that there’s only one way at the problem.
High quality Cisco, HP, IBM, Oracle and other Certification exmas training materials are provided here atPass4sure Pass4sure helps you on your way to your certifications,Click 640-802 to get more information!
High quality Cisco, HP, IBM, Oracle and other Certification exmas training materials are provided here at Pass4sure Pass4sure helps you on your way to your certifications,Click 640-553 to get more information!
Manually constructing object graphs like you suggest here works fine for small-ish projects but easily gets out of hand in larger ones, particularly if such projects are broken up in multiple projects/ modules/ libraries. Modules provide an excellent mechanism to hide complexities of how such libraries are composed. You could achieve the same by providing builders and such, but then you’d be handwriting what a DI framework already provides. Also, @ImplementedBy and lazy binding provide an excellent way of reducing dumb setup code; in my experience, an composition of a module system uses defaults maybe 70 or 80 % of the time, so your bootstrapping code only has to configure composition for a relatively small number of cases.
Without the concept of dependency injection, a consumer who needs a particular service in order to accomplish a certain task would be responsible for handling the life-cycle (instantiating, opening and closing streams, disposing, etc.) of that service.
Very nice work you have there, thank you for sharing with me. Been looking for such code for a while now.
I actually prefer using xml, mostly because I understand it.
i think Dependency Injection has gained lots of popularity in last two to three years. It is mainly getting popularity because of its code simplification effects. lots have already been said DI benefits and i think there is more to say. So thanks for this article and keep contributing on benefits of DI.
i think Dependency Injection has gained lots of popularity in last two to three years. It is mainly getting popularity because of its code simplification effects. lots have already been said DI benefits and i think there is more to say. So thanks for this article and keep contributing on benefits of DI.
(sorry for double comment, i request to remove the above comment)
I always prefer PHP with Ajax for fast results.
Any idea how often Google’s Guice framework updates?
I think multiple factory can make your things more messy.
You should look for some other reliable and proper options.
I also find XML easier to understand. However, I understand the benefits of Java Scripting, CSS and the like.
Thank you for this. It was a very interesting discussion to read.
Wow. Amazing insight! Thanks for this! Saskatoon SK Real Estate
Great work! This is really interesting stuff. Looking forward to reading more.
Definitely agree with what you stated. Your explanation is certainly the easiest to understand about dependency injection.
Awesome code!
Very good article, thanks for the tips. It is useful even for beginners
Thanks for this awesome code!
Thanks for your view on dependency injection, we are in the process of selecting and using our first DI framework. Your post helps to determine where to use automatic DI.
I am very thankful to you. The code made my project working. I got total output
OK, just have a free try!!
it is good to know how we can prevent… thank you for the tips
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your post
i found this in google search, very intersting article, thanks for sharing
great post almost understood it. my programmers handle all my xml stuff….now i see why.
go to wow very good
Thanks for the code. I’ve never tried these things before and wonder if it can be done. Will it give a night shot, a long reading, but certainly worth it. Thank you.
Using XML to inject dependencies is a total nightmare. What reasonable person would do that? This outline is a much more effective approach.
Thanks guys for the publication of this material. I’ll use your code.
Nice post, I’ve really enjoyed reading your articles. You obviously know what you are talking about! And Your site is so easy to navigate too, great blog.
Thanks for theNice post, I’ve really enjoyed reading your articles. You obviously know what you are talking about! And Your site is so easy to navigate too, great blog. code. I’ve never tried these things before and wonder if iNice post, I’ve really enjoyed reading your articles. You obviously know what you are talking about! And Your site is so easy to navigate too, great blog.t can be done. Will it give a night shot, a long reading, but cerNice post, I’ve really enjoyed reading your articles. You obviously know what you are talking about! And Your site is so easy to navigate too, great blog.tainly worth it. Thank you.
hmmmmm,. I don’t know this post ;) but, I think it’s great,.. and maybe I can learn about it latter,. great blog,. keep share!,. ty
Hah,that was really funny. I even ordered an essay paper on it.These online essay writers made an excellent essay for me. Granite Colors | Granite Countertops | Granite VA | Granite MD | Granite Remnants Granite Maryland | Granite Virginia
Hi, I would like to thank everyone the hard work you spent as Google’s Guice framework Thankyou
Thanks for the tips on framework and putting in terms I can understand:)
Thanks for the code. I’ve never tried these things before and wonder if it can be done.
I tried it and it works… thanks… now my application is safer
Great – tried & tested, many thanks!
Thanks, it was usefull code for me!
For me too!
We only use constructor injection and use StructureMap to auto wire it up. All we need is:
Scan(x => { 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.
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 :)
Yes, both Windsor and StructureMap make it easy to register the whole application using very little code.
I’m still not sure what the appeal is for javascripting, CSS, etc.. I prefer sticking to XML personally. At any rate, I appreciate the read.
Cheers.
I really like this new version. Wanna support for this for further development. I had some good command on the Arabic language. So I can satisfy well with this blog.
Thanks for theNice post, I’ve really enjoyed reading your articles. You obviously know what you are talking about! And Your site is so easy to navigate too, great blog. Trendy Fashion Jewelery, erwinwellen, Home Improvement Tips
I can confirm that this works. thank you for the wonderful tip.
I am glad that the windsor registration was so smooth. It was just a few lines of code and it implemented without a hitch.
It was just a few lines of code and it implemented without a hitch.
virtual expos online from the comfort of your own home.
for a safer application it is better to prevent this kind of injection. I tried that code and it works. you can use it!
I too can confirm that this works
I tried that code and it is safe… you can not hack my database anymore. Thanks!
virtual expos online from the comfort of your own home.
Using XML to inject dependencies is a total nightmare. What reasonable person would do that? This outline is a much more effective approach.
Nice. I used all of these protection methods in my website.
Thanks for the explained process. I am very familiar with the entire set-up, and have done work almost identical to the ones shown.
Bob Lee wrote:
What happens when you need to inject TransactionLog into a 2nd constructor? You have to type “TransactionLog tl = new DatabaseTransactionLog()” again. With Guice, you do nothing. What happens when you use TransactionLog in 100 places?
Guice let’s me to postpone the decisions of what concrete instances to use, but I hope that we don’t forget that delaying commitment on design issues is beneficial too: Speculative design has it’s costs, and I’d prefer to use factories only after I have noticed it to be necessary, and Guice or any other DI FW only after I have decided that I need one.
Hello All, I just wanted to start by saying that the contribution here is simply amazing.
Hiya. I’m definitely interested on this subject. Might you be publishing anything at all else about this?
Inyections in weak scripts can simply break the codes… specially when dealing with open source scripts
This article has given me some interesting points on scripting.
Now that is one hell of a article. I could only dream of doing something like that !
This article gives the light in which we can observe the reality. This is very nice one and gives in depth information. Thanks for this nice article. Good post…..Valuable information for all.
Great article, a bit over my head but definitely some new concepts learned.
Several frameworks that will help you inject dependencies into your system can be found all over the internet. If you need particular software or webservice, here is where to find your website development experts.
Thanks for the article. Good examples of code. I would use.
Without the concept of dependency injection, a consumer who needs a particular service in order to accomplish a certain task would be responsible for handling the life-cycle (instantiating, opening and closing streams, disposing, etc.) of that service.
Romance is out of summer, the perfect period. Outing Romantic, melting snow spins dress is today season vogue girls wear build up the important sheet is tasted, using qualitative produce elegant light spins the romantic sense, plus the broken this year popular element , presents different female glamour. The frivolous fabrics spins or cultivate one’s morality is best, clear and elegant texture to help you hide fat shape, block butterfly arm.
Flower skirt seems to be in summer, forever ChanYi as thin as the flower skirt, can not only a cool summer, and all sorts of design and color, let you do in summer “ever-changing princess”, plus all sorts of collocation, individual character is dye-in-the-wood, the flower skirt collocation of snow, cowboy ma3 jia3, formed the integral style of contrast, let you both cooling and handsome!Tie-in skill: flower skirt handsome ma3 jia3
this dependency injection resource is unparalleled on the entire WWW
However If you’re interested in finding Funny SMS Collection or latest Birthday SMS or great collection of Friendship SMS then go to CuteSMS.net to find them out.
Now that is a good article. I could only dream of doing something similar
What is this? Jk This is soo complex
how can I use it for my site? how can I have a safe database?
Its extremely important to know where all the instances are created, if you dont, you loose track and control of the structure of the object that is being coded. Naturally, I believe we tend to not author protocols and hence loose track of the core issue, which is in my opinion, control. thanks.
I have never thought that surfing online can be so much beneficial and having found your blog, I feel really happy and grateful for providing me with such priceless information.
this dependency injection resource is unparalleled on the entire WWW
iPhone Ringtone Custom turns your dream of making your own iPhone/iPhone 3G Ringtone with loved music into reality in the way of converting almost all mainstream video/audio format to M4R iPhone ringtone, such as avi, mpeg, mp4, mov, flv, mp3, aac, m4a, wma, etc. to M4R iPhone Ringtone, even rip DVD Disc to Ringtones for iPhone. Convert to iPhone Ringtone Change iPhone Ringtone Convert Music to iPhone Ringtone Convert MP3 iPhone Ringtone Convert M4A to M4R Convert MP4 to iPhone Ringtone
yes this does work. thanks!
This was a good read, kinda early in the morning though. Should do some work Laughing lol
Good post. I am also going to write a blog post about this…
This looks absolutely perfect. All these tinny details are made with lot of background knowledge. I like it a lot. Keep on taking action!
Excellent information here. This blog post made me smile. Maybe if you put in a couple of pics it will make the whole thing more interesting.
I like how you managed to put all the Guice stuff inside a factory. I do expect, though, that in a real application, with multiple factories for different object, it would become a bit messy. But it’s concentrated mess.
I have to ask – when do you consider moving from hand written test doubles to a framework? And where in a TDD process would you decide that?
Gil Zilberfeld
Typemock
This was a really quality post. In theory I’d like to write like this too,taking time and real effort to make a good article…
Wishing you the best of luck for all your blogging efforts.I will revisit your website for additional information.
Manually constructing object graphs like you suggest here works fine for small-ish projects but easily gets out of hand in larger ones, particularly if such projects are broken up in multiple projects/ modules/ libraries. Modules provide an excellent mechanism to hide complexities of how such libraries are composed. You could achieve the same by providing builders and such, but then you’d be handwriting what a DI framework already provides. Also, @ImplementedBy and lazy binding provide an excellent way of reducing dumb setup code; in my experience, an composition of a module system uses defaults maybe 70 or 80 % of the time, so your bootstrapping code only has to configure composition for a relatively small number of cases.
One issue in this example is in your presumption of how DI frameworks are generally used. I think it’s important to draw a distinction between Dependency Injection and the Service Locator pattern here.
DMOZ Directory or ODP is a human managed directory that sends results or data to search engines. DMOZ directory data is now used by the majority of major search engines on the net.
This was a really quality post. In theory I’d like to write like this too,taking time and real effort to make a good article…
Thank you very much for this article.I like its.As to me it’s good job.
e-lottery has thousands of members worldwide, all of whom enjoy the advantages that membership brings. Since its inception and the start of trading operations, e-lottery has paid out millions of pounds in winnings to its syndicate members and millions of pounds in commission to its Business Affiliates.
One issue in this example is in your presumption of how DI frameworks are generally used. I think it’s important to draw a distinction between Dependency Injection and the Service Locator pattern here.
Crazyvids.org is a website designed for sharing with our visitors the craziest and funniest videos we can find on the internet.
thanks for your sharing, I appreciate this. keep up the good work
I used Guice in a real life project (about 140k lines of code). It did make life easier, but the guys who where supposed to continue developing, decided to build around it, because they didn’t understand how my “bunch of secret modules” worked. They said they like the architecture, but don’t understand how the wiring works. That sucked. Explaining didn’t help either.
Regards
Great blog it’s not often that I comment but I felt you deserve it. I enjoyed reading it!
Too many comments to read, but I wanted to mention that with Spring (I don’t know Guice) the benefits of letting Spring create instances for you is that you get support for other mechanisms: 1. bean factories: which let you conform non-beans into the java beans pattern 2. property placeholders (which otherwise means the bean needs to have a reference to the Properties object in order to configure itself) 3. bean post processors 4. XxxAware interfaces which allow to auto inject values to a bean
5. In fact, for me the advantage of Spring is not because it is an DI container, but because it creates a lifecycle for my beans (services)
This blog is very nice.I will keep coming here again and again.Visit my link as follows: watches <\a>
Incredible share. Amazing article. Love this facts. Thanks for the great work.
Paula from MDR-RF925RK MDR-IF240RK Sennheiser HD 202 Record Label Business Plan
Thank you very much for this article.I like its.As to me it’s good job. cheap replica rolex cheap replica omega manmall replica rolex
This article gives the light in which we can observe the reality. This is very nice one and gives in depth information. Thanks for this nice article. Good post…..Valuable information for all. Gaming Wireless Router Greets J.V
t is mainly getting popularity because of its code simplification effects. lots have already been said DI benefits and i think there is more to say.
Without the concept of dependency injection, a consumer who needs a particular service in order to accomplish a certain task
Well done! Looking for more interesting post from your end. Thanks a lot!
you sen admin thanks
the best downloads warez release : http://www.httpdl.com
excenlent writing, informative and well structure. a particular service in order to accomplish a certain task
Drug 4 Health
I remember this show, which will benefit both will remember. Each month, so that rewatched the first cycle of a new one.
Such a long list of comments..
Well written article.. Good Job
It was a great post and informative too.Thanks for sharing.
It’s a good blog. It’s a really good blog. Oh I don’t mean his silly complaining about C++ or Templates or COM.
nd sure there are “architecture astronauts” that understand how and why to use specific technologies, but in my experience most people only think they know these things, creating maintenance nightmares.
I found that when I wanted more information the links provided me with what I was looking for.
Great ideas and tips. I’ve always had trouble finding a free place to blatantly a dvertise my products and services so I made one.
Interesting. His point is that by overusing DI frameworks, we are creating an application that has a strong dependence on these, we have to invest.
Uncle Bob, thanks for the wonderful post. I don’t always agree with what you have to say (and that’s a good thing) but this one I thin hit the nail succinctly and elegantly on the head.
This is the best thing that i read. thank you guys for this great stuff!
Uncle Bob, thanks for the wonderful post. I don’t always agree with what you have to say (and that’s a good thing) but this one I thin hit the nail succinctly and elegantly on the head.
ah. this tutorial what i looking for.thanks for providing this. i need it for my college work
Some great info here, but as you say surely it is easier creating concrete instances rather than all of this overblown stuff. Maybe it would be better working on much larger apps but a bit overcomplex for my needs. Much prefer the simpler way that you laid out.
This tutorial has really helped, thank you so much.
This is very interesting and quite informative. Gotta be honest i dont get it 100% but im still learning… Also i dont really understand how this is controversial… But maybe its just over my head.
Really very good post. I really appreciate for this post. keep posting up. I learned something new.
This is very interesting and quite informative. Gotta be honest i dont get it 100% but im still learning… Also i dont really understand how this is controversial… But maybe its just over my head.
I expect that in a real application, with multiple factories for alternative object, it would probably become a little messy.
Awesome. I just tried the code and it works wonderfully
Me too prefer Ajax + PHP
Great post. I’m very impress with this post,Thanks for sharing this information.
cheap VPSReally very good post. I really appreciate for this post. keep posting up. I learned something new.
Like one of the earlier posters said, I don’t always agree with what you say but this one is right on.
Thanks a lot for this post. It’s incredibly informative. If you do not mind, I have a question; How do you deal with Spam in blog comments? I genuinely hate it, It wastes my time and I hate dealing with it each day. Do you have any suggestions for what I can do to reduce the quantity of comment spam I get on my blog? Thanks for your suggestions.
A boaster and a liar are cousins-german.
This looks good and true.
I also prefer php+Ajax
I learned a long but not too .. thanks Adda results may be useful for my article
i aslo prefer php it’s much good for this !!!!
very good blog and interesting blog thanks a lot
This is the best thing that i read. thank you guys for this great stuff!
Th4t be an epic da shizzi4 post, th4nkie 4it & in da futures we’ll be seeing more of it
We7ll I8be dat9 ogr6e speekie da speekie, gratz & than4x
heb7e sh8at be th34nkie 4it on da posting left & righ8ty
Hope you go on like this… good luck!
Like one of the earlier posters said, I don’t always agree with what you say but this one is right on.
Is it so good?
Good blog and I liked it.Thanks for posting.
Thanks For Sharing :)
In this article, she look so amazing. She always prepare a performance maximally. That great!
yeah. I get it now of this Dependency Injection Inversion.
Thanks a lot for this post.It is very informative.But one thing i clarify from you….... How do you deal with Spam in blog comments? I genuinely hate it, It wastes my time and I hate dealing with it each day. Please suggest me what to do. http://www.chichilnisky.com/
I like your blog.You provided such a good blog.It contains all the relevant information. http://www.fabricarehouse.com/
Very informative post thanks for the effort you have put into this.
Very informative post, thanks for sharing
Nice blog and i like the new content. http://surfaceid.com
Now that is one hell of a article. I could only dream of doing something like that !
Very nice art, thanks !!! —-—-—-—-—-— laptopy sklep
Good blog and I liked it.
Why not enable feed (RSS) on you blog. It would be nice
Resources like the one you mentioned here will be very useful to me
It is very informative.But one thing i clarify from you. How do you deal seo with Spam in blog comments? I genuinely hate it, It wastes my time and I hate dealing with it each day.
Our jewelry designer Tom Babilla has taken the designer jewelry world by surprise. What is even more interesting is that all the collections are handcrafted and require great ability to finally give a good finish.
Sounds like OOP to me, I personally dislike having to code it myself.
~John
Awesome blog, i love it. I have subscribed to you my friend. Keep the good work up your getting there hehe!
Technology and Blogging Tips Thanks!!
Good keep it up my friend!
Hi, are you comparing your self with google, I’ve saw some other topics like this on different forums but Have had a great fight with peoples there.
discussing on same topics, I think google is pretty big company to compare with.
What is even more interesting is that all the collections are handcrafted and require great ability to finally give a good finish. seo
This looks absolutely perfect.I definitely agree with what you stated. Your explanation is certainly the easiest to understand about dependency injection. craigslist tampa
its a very very gud thing for me because i have need this.. thanks for very informaitve post its nice i like it
its a nice blog i like it u done the gud job
its a very very gud thing for me bethanks for very informaitve post its nice i like itcause i have need this..
I always use PHP because I think it is much more easier to use. For example, in this site Power4home , I used Php
I forgot to mention that php is also better because it is much more efficient to use and the accessibility is awesome. On more example is this greendiyenergy
I really like this new version. Wanna support for this for further development. I had some good command on the Arabic language. So I can satisfy well with this blog.
I agree with PHP definitely being easier to use, but this info is still very helpful.
PHP is too easy and not many functionality
Resources like the one you mentioned here will be very useful to me
this post is asome
LV belt, LV belts, LV belts for men, LV Mens belts.
Some actually seem like they are created with space creatures – not real women – in mind. But this fall, designers rolled out a multitude of great wearable looks.
thank you
Very interesting, thanks for sharing!
This looks absolutely perfect. All these tinny details are made with lot of background knowledge and it is very usefull. Thanks. I like your writing style, don’t change!
Thanks for this great post. Read about blood sugar levels.
Thanks for this post. Read about health symptoms.
essay company
essay writing
Thanks for this article…really useful!
Thx!
Fantastic post. Bookmarked this site and emailed it to a few friends, your post was that great, keep it up.
Thanks for sharing this useful post. Read about kidney infection symptoms.
Php is always good but the learning curve is steep. right? I am a webmaster of Frontierville Cheats so I have a bit of a background.
BillingModule and BillingServiceFactory both extend AbstractModule and do the same binding. Is this necessary to make things work?
Fantastic post. Bookmarked this site and emailed it to a few friends!
Thanks for sharing this useful post.
Good job!
Interesting post man!
I like all informations from your blog!
Best texts!
dupont lighter, dupont lighters, st dupont lighter, s.t. dupont lighters. Great post,just as Great belts Sale time,you will enjoy the shopping time by belts Sale online store,and buy belts from belts Sale online store. Price Guarantee, sale now.time limited.seize the chance.
gucci wallet, gucci wallets, mens gucci wallet, women gucci wallet.
Price Guarantee, sale now.time limited.seize the chance.
Hermes belts, Elegant Hermes belt, Fashion Hermes belts for men, Hermes mens belt.
Great post,just as Great belts Sale time,you will enjoy the shopping time by belts Sale online store,and buy belts from belts Sale online store.
Men’s belts, LV men’s belts, Fashionable Gucci men’s belts, Attractive style Hermes men’s belts.
This florist in Kensal Rise is an olfactory sensation, overflowing with flowers, foliage and stacks of ancient-looking vases and crockery. It all looks as if Vicky, the owner, has picked the flowers fresh from the meadows that day.
LV belt, LV belts, LV belts for men, LV Mens belts.
Some actually seem like they are created with space creatures – not real women – in mind. But this fall, designers rolled out a multitude of great wearable looks.
The Haizhouwan fishing ground, one of the eight largest fishing grounds in China, has more than 20 different kinds of fish and shrimps anda dozen different kinds of shellfish
Nice Blog and Article. This is some indepth info.
so good post i like it china nfl jerseys
Not sure what these other posts are about but I am grateful for the info on Dependancy Injection. Wil watch out for future posts as I am trialing it on my Designer Watches website for ladies and gentlemen. Thanks again.
I like your clean code for dependency injection inversion also I learn to write good code using your samples. what will be the code in case of singleton instead of factory patterns.
Summer Dresses | Sports Discussion | Submit URL | Articles Writing | Pakistan Affairs
Very nice.
I agree with you.Good Article by the way, I will be forwarding it onto my boss.
Thanks!
Nice post. Well written and interesting. Thanks for sharing the information.
Substantially, the article is really the best on this laudable topic. I concur with your conclusions and will eagerly look forward to your future updates. Just saying thank you will not just be enough, for the wonderful lucidity in your writing. I will instantly grab your rss feed to stay abreast of any udates. Gratifying work and much success in your business endeavors.
Thanks to all of them for making startups possible. And, most importantly ,So, there you have it. As fun as it has been to joke about it.
Hi there i like your unique site, I wuold be very honored if you would want me to write a review on your awesome work on my Blog would you be ok with that?
Brilliant post! It created enough of a stir for people to post replies on their blogs leading to valuable insight into various frameworks. Now my DI framework usage is clean, simple and does wonders. Thanks, it really made my day!
Very informative post thanks for the effort you have put into this.
Of course Guice seems excessive and the example with two units and a specific scope and life. What if some of the units need to be created by HttpRequest, some are created each time new and some are unique? Are you going to write a factory for each area? I think improvement would be a good solution. In fact, many schools didn’t care about the curriculum and just went with their own rules.
Nice post, but it’s too much spam in comments.
Thank you very much Great post…thanks for share this
Thank you very much Great post…thanks for share this
nice share
This was exactly what i was searching for. Have been fighting for a while to do this, thanks for have posted
High Weeds – All about Marijuana
I think these frameworks are great tools. But I also think you should carefully restrict how and where you use them.
Very helpful,thank you so much for this great article..I interested Injections..
Mvc framework in asp has caused some quite advances issues for our programmers. Dependencies include controller, views and more. We have been successful at implementing it, at a quite high price though. It takes some time to get used to the dependency inversion model.
Get the best Prepaid Credit Card to fit your needs. Everyone is approved with out any credit checks or bank accounts needed.
Get the best Prepaid Credit Card to fit your needs. Everyone is approved with out any credit checks or bank accounts needed.
Thanks for the code uncle Bob
Awesome job Uncle bob:)
Very informative post thanks for the effort… :)
This was exactly what i was searching for. Have been fighting for a while to do this, thanks for have posted
very interesting. I will bookmark this article, and I will read it carefully
It helped me with ocean of awareness so I really consider you will do much better in the future.
Inversion of Control (IoC) means that objects do not create other objects on which they rely to do their work. Instead, they get the objects that they need from an outside source (for example, an xml configuration file).
Dependency Injection (DI) means that this is done without the object intervention, usually by a framework component that passes constructor parameters and set properties.
I use structure map to auto wire my dependencies and can usually get away with 10 to 20 lines of code.
i like your things very much ,very deep, so nice
i like your articles, this is good post ,good blog
Well worth the read. Thanks for sharing this information. I got a chance to know about this.