How do I subtract a binding using a Guice module override?
Posted
by Jimmy Yuen Ho Wong
on Stack Overflow
See other posts from Stack Overflow
or by Jimmy Yuen Ho Wong
Published on 2010-05-18T04:04:57Z
Indexed on
2010/05/18
4:10 UTC
Read the original article
Hit count: 300
So according to my testing, If you have something like:
Module modA = new AbstractModule() {
public void configure() {
bind(A.class).to(AImpl.class);
bind(C.class).to(ACImpl.class);
bind(E.class).to(EImpl.class);
}
}
Module modB = New AbstractModule() {
public void configure() {
bind(A.class).to(C.class);
bind(D.class).to(DImpl.class);
}
}
Guice.createInjector(Modules.overrides(modA, modB)); // gives me binding for A, C, E AND D with A overridden to A->C.
But what if you want to remove the binding for E in modB? I can't seem to find a way to do this without having to break the bind for E into a separate module. Is there a way?
© Stack Overflow or respective owner