I'm going to point you in the direction of a Guice best-practice guideline which strongly suggests not doing what you've chosen to do.
https://github.com/google/guice/wiki/InjectOnlyDirectDependencies Specifically, months down the road what if MyObject also needs a BarService? And then a BazService? Now you're going to have a bunch of hand-written specific code to do exactly what Guice is supposed to do for you for free. When does the madness end?! =) Good luck, Nate On Thu, Oct 2, 2014 at 12:41 PM, Kevin Burton <[email protected]> wrote: > I think I answered my own question :-P > > I think the strategy is to always inject in the constructor. This way the > entire application won't startup. > > Even if it's rarely used, having it from the start of the application will > fix these problems and your app won't compile without this object in the > constructor. > > > On Wednesday, October 1, 2014 9:33:42 PM UTC-7, Kevin Burton wrote: >> >> I'm curious what the best practice is here. >> >> Let's say that deep in your code you wanted to create a new instance of >> MyObject and pass it a FooService... >> >> One could use an injector to do this.. but what if we actually forgot to >> bind anything to FooService? >> >> You would deploy your application, it would be running just fine for >> months, then all of a sudden you would need FooService and your app would >> fail. >> >> How does one avoid that scenario? >> >> If you used explicitly provided dependencies, your app would fail at >> compilation time. >> >> Now we've postponed to fail at run time.. which is not fun. >> >> Any solutions here? >> > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/google-guice. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-guice/579a3e9d-c1b6-47f2-b21b-8a7b0f56824b%40googlegroups.com > <https://groups.google.com/d/msgid/google-guice/579a3e9d-c1b6-47f2-b21b-8a7b0f56824b%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice. To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/CAHNex99jxsa6%3DhFhfraxr_XUYJU0c4fU43BTNf8byTWdP6ZmWg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
