Guice child injector override binding
Posted
by Roman
on Stack Overflow
See other posts from Stack Overflow
or by Roman
Published on 2010-05-13T09:01:42Z
Indexed on
2010/05/13
9:04 UTC
Read the original article
Hit count: 187
Hi All
I am trying to to override a binding in a child injector that was already configured in a base injector.
like that :
public class PersistenceModule extends Abstract{
@Override
protected void configure() {
bind(IProductPersistenceHelper.class).to(ProductPersistenceHelper.class);
}
}
then :
Injector injector = Guice.createInjector(new PersistenceModule());
injector.createChildInjector(new AbstractModule(){
@Override
protected void configure() {
bind(IProductPersistenceHelper.class).to(MockProductPersistenceHelper.class);
}
})
Guice is complaining that it has already a binding for that. Are there any patterns or best practices for that problem ?
© Stack Overflow or respective owner