There's two different options that could have helped here: Binder.requireAtInjectOnConstructors -- This will refuse to construct anything that doesn't have an annotated constructor.
Binder.requireExplicitBindings -- This will refuse to inject anything that doesn't have an explicit binding in a module. sam On Apr 9, 2014 5:39 PM, "Robert Donovan" <[email protected]> wrote: > Hello all, > > I ran into a bit of an issue today which went something like this: > > 1) Class Foo had a dependency on class Bar, which is in a third-party > library. Bar is a parameterized type, but Foo doesn't care about that, so > the constructor looks something like this: > > @Inject > public Foo(Bar<?> bar) { > ... > } > > 2) The associated module had an incorrect binding, where the parameterized > type was specified as byte[]: > > bind(new TypeLiteral<Bar<byte[]>>() {}).toProvider(...); > > 3) Despite this, because Bar has a no-args constructor, it seems Guice > just silently created an instance of it when instantiating Foo, which > caused various issues. I would prefer it to have bombed out on this > occasion as the result was quite tricky to debug. > > I'm interested to know what you guys think about this. Technically my > bindings were wrong, but silently injecting an incorrect instance caused a > lot of pain. Are there ways to ensure such scenarios fail fast? I guess > requireBinding would be the only way? > > Thanks, > Rob > > -- > 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. > 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. For more options, visit https://groups.google.com/d/optout.
