On Wed, Feb 10, 2010 at 12:21 AM, Colin Decker <[email protected]> wrote: > This probably isn't ideal, and I don't know if you can control how the > RobotModule gets added to the injector, but you can wrap RobotModule in a > PrivateModule: > public static class PrivateRobotModule extends PrivateModule { > �...@override > protected void configure() { > install(new RobotModule()); > bind(Robot.class); > expose(Robot.class); > } > } > If you use that instead, the RobotHeart binding won't be exposed. Then you > can do: > public static class TitaniumRobotModule extends PrivateModule { > �...@override > protected void configure() { > install(Modules.override(new RobotModule()).with(new AbstractModule() { > �...@override > protected void configure() { > bind(RobotHeart.class).toInstance(new RobotHeart("titanium")); > } > })); > } > �...@provides @Titanium @Exposed > protected Robot provideTitaniumRobot(RobotHeart heart) { > return new Robot(heart); > } > }
Wow, I didn't know about install()! Or Modules.override()! This example is a bit of gold and solves most of my current problems. This example has taught me a great deal about features which aren't documented on the user's guide. Assuming the user's guide allows public edits, I will update it once Google hosting is no longer read-only. -- 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.
