4 ms·
I don't know your codebase, but I'm going to propose that your (and that blogger's) projects could be even messier without Guice. As the blogger points out, the
by stickfigure 10y ago
I don't know your codebase, but I'm going to propose that your (and that blogger's) projects could be even messier without Guice. As the blogger points out, the "simple alternative to DI" is:
BillingService billingService = new BillingService(new BillingModule());
...which looks fine with just a couple layers of depth but becomes pathological with hundreds of objects, especially when they have different lifecycles. At some point the extra transparency you get from manual injection is overwhelmed by the sheer quantity of boilerplate.
To compensate, DI-less solutions end up with service discovery or "bag" classes like DropWizard's io.dropwizard.setup.Environment. Aside from the loss of encapsulation, what if you want to extend the framework with new components? You end up exposing services by setting attributes with text keys...
Having a messy Guice-based project doesn't mean it would be pretty without Guice.