As some of you probably have heard, Uncle Bob was recently criticizing Guice and DI frameworks at http://blog.objectmentor.com/articles/2010/01/17/dependency-injection-inversion
Here are some things that he said: "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." "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." "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." "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." Then he goes on to describe how he would wrap Guice into a factory, which in turn is stored as a public static mutable field in a class, and says about it: "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." Since Uncle Bob's writings tend to get much publicity, it would be nice for the Guice authors to give an public reply to the arguments raised by Uncle Bob. Otherwise the public opinion about Guice might be distorted. At least these questions would need an answer: - Why was Guice designed to require the constructors to be annotated with @Inject? - Why the statement "I don’t want to have createInstance calls scattered all through my code" does not hold water? (Personally I think that Uncle Bob has misunderstood how Guice and DI frameworks should be used - only one bootstrap class should be aware of Injector. Also I think that the @Inject annotation is good, because it makes it explicit that which classes are instantiated with "magic" and you should look into the DI config for more details. Also the requirement for @Inject or a hand-written Provider will avoid accidentally instantiating a class which was not meant to be instantiated by the framework.) -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
