I experienced a similar issue where in some test case a module was
installed twice.
This worked fine until I added a AssistedInjection binding which caused
a whole bunch of tests to fail with an binding already exists error.
Fixing it in my code was simple since it only involved unit tests and I
could just remove the second call to install().
On 11/04/2013 07:24 PM, Sam Berlin wrote:
We've fixed the mapbinder/multibinder issued in HEAD (haven't made it
into the beta release yet). But in general, you shouldn't rely on
module deduplication. Guice also does binding reduplication if the
bindings are exactly the same too. Binding deduping is generally
better, and safe through Modules.override.
sam
On Nov 4, 2013 12:51 PM, "Tavian Barnes" <[email protected]
<mailto:[email protected]>> wrote:
Since Elements.getElements() creates a flat list of bindings,
constructions that rely on module de-duplication in install()
don't work perfectly with module re-writing. For example:
interface Interface {
}
static class Implementation implements Interface {
}
class Module1 extends AbstractModule {
@Override
public void configure() {
bind(Interface.class).toInstance(new Implementation());
}
@Override
public boolean equals(Object obj) {
return obj instanceof Module1;
}
@Override
public int hashCode() {
return 0;
}
}
class Module2 extends AbstractModule {
@Override
public void configure() {
install(new Module1());
install(new Module1()); // Fine
install(Elements.getModule(Elements.getElements(new
Module1()))); // A binding to Interface was already configured...
}
}
This is especially noticeable with things like
Multibinder/MapBinder which rely on module de-duplication.
My idea to fix this is to add an Element implementation
"InstalledModule" or something that would hold the bindings from
installed modules, and replay them only if the module wasn't
already installed in the target binder.
That's obviously a pretty big change though. Is there a better
way I could approach this? Is a "fix" even desired?
--
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]
<mailto:google-guice%[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.
--
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/groups/opt_out.
--
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/groups/opt_out.