Re: Any way to override bindings?

2014-02-18 Thread Tim Boudreau
I think the mention of inheritance at the top of this thread sent it off 
in some weird directions.  You don't have an inheritance problem.  You have 
a one module binding orthagonal things problem.

Split the stuff that will not be overridden out of your parent module. 
 Create a new module - we'll call it common that binds that stuff.

For the remainder, have two modules, and only use one of them at runtime. 
 One will be your stock bindings, and the other will be your customized 
bindings.


It's really rare to need inheritance in writing Guice modules (or most 
anything, really);  thinking in terms of inheritance can blind one to 
really simple composition-based ways of solving problems.

-Tim

-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Any way to override bindings?

2014-01-21 Thread Sergiy Sokolenko
You can also use com.gogle.inject.util.Modules.override(Module... modules) 
to override bindings as suggested by @albertb at 
http://stackoverflow.com/questions/483087/overriding-binding-in-guice

On Saturday, March 17, 2007 5:45:24 AM UTC+2, ajoo@gmail.com wrote:

 Hi there.

 We have a parent project and a child project. The child project is a
 customization of the parent project, where some of the interfaces in
 parent project will have different implementation classes.


 What I was thinking that we could do was to subclassing a Module as:

 parent project:

 class MyModule extends AbstractModule {
   protected void configure() {
 bind(Interface1.class).to(Class1.class);
 bind(Interface2.class).to(Class2.class);
 ...
   }
 }

 child project:
 class SubModule extends MyModule {
   protected void configure() {
 super.configure();
 bind(Interface2.class).to(Subclass2.class);
   }
 }

 This way I'm hoping that sub module will use almost every setting in
 parent project with the implementation class of Interface2 changed to
 Subclass2.

 But if I'm not mistaken, Guice isn't happy about this. An interface
 can only have one bindings.


 I'm trying to think of a workaround or a better solution. At the same
 time, hope some of you guys may shed some light for me.

 Ben.



-- 
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 google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.