Thanks for the suggestion... On Tue, Feb 9, 2010 at 3:24 PM, Brian Pontarelli <[email protected]>wrote:
> On Feb 9, 2010, at 12:43 PM, Evan Gilbert wrote: > > > Trying to solve a use case in Guice that's similar to Robot Legs, but the > existing solutions don't seem to map. > > > > Use case (code below): > > - Have an existing Robot class with @Injected constructor that takes a > RobotHeart > > - Have existing RobotModule that provides a set of bindings for robot > parts, including a binding for RobotHeart > > - Can't modify RobotModule or Robot > > - I want to be able to inject a Robot instance with a different > RobotHeart binding, i.e. > > @Inject @TitaniumHeart Robot; > > creates a robot with a different injected heart. > > > > The PrivateModule solution doesn't seem to work, because it would create > a duplicate key for RobotHeart.class and duplicate keys aren't allowed. > > > > Any thoughts on how to implement? > > Doesn't subclassing work? What issues are you having with that type of > solution? > Subclassing can probably work for my use case but I would prefer not to if there are alternatives: - It's fragile and more likely to break when the parent class changes - Won't work with deeper injection trees - you have to subclass the whole tree above the injected class. So if a Robot has a RobotLeg with a RobotFoot with RobotBigToe and I want to provide a different big toe, I have to subclass Robot, RobotLeg, and RobotFoot. - It also seems to be a bit counter to the spirit of injection. But... this may work and I'll probably move forward with it if there aren't other alternatives. > -bp > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
