robot-legs-problem

Can the Cake Pattern be used for non-singleton style dependencies?

对着背影说爱祢 提交于 2020-01-01 14:22:31
问题 Most of the examples of the Cake Pattern I've come across appear to consider dependencies as singleton type services; where there is only one instance of each type in the final assembly of components. Is it possible to write a configuration that has more than one instance of a particular type, perhaps configured in different ways, when using the Cake Pattern for dependency injection? Consider the following components. Generic HTTP service: trait HttpService { def get(query:String):String }

Can the Cake Pattern be used for non-singleton style dependencies?

旧巷老猫 提交于 2020-01-01 14:22:29
问题 Most of the examples of the Cake Pattern I've come across appear to consider dependencies as singleton type services; where there is only one instance of each type in the final assembly of components. Is it possible to write a configuration that has more than one instance of a particular type, perhaps configured in different ways, when using the Cake Pattern for dependency injection? Consider the following components. Generic HTTP service: trait HttpService { def get(query:String):String }

Generalize guice's robot-legs example with Multibinding

徘徊边缘 提交于 2019-12-18 04:59:07
问题 I have this use case that is very similar to the robot-legs example of Guice, except I don't know how many "legs" I have. Therefore I can't use the annotations needed for the robot-legs example. I expect to gather all these "legs" in an java.util.Set with Guice's Multibindings extension. Technically, in a PrivateModule I would like to expose an implementation directly as an element of the set that will be provided by the Multibindings extension. I just don't know how to do that. For reference

How do I bind Different Interfaces using Google Guice?

寵の児 提交于 2019-12-01 06:31:50
Do I need to create a new module with the Interface bound to a different implementation? Chef newChef = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl.class); } }).getInstance(Chef.class); Chef newChef2 = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl2.class); } }).getInstance(Chef.class); I cannot touch the Chef Class nor the Interfaces. I am just a client binding to

How do I bind Different Interfaces using Google Guice?

孤街浪徒 提交于 2019-12-01 05:13:48
问题 Do I need to create a new module with the Interface bound to a different implementation? Chef newChef = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl.class); } }).getInstance(Chef.class); Chef newChef2 = Guice.createInjector(Stage.DEVELOPMENT, new Module() { @Override public void configure(Binder binder) { binder.bind(FortuneService.class).to(FortuneServiceImpl2.class); } })

Generalize guice's robot-legs example with Multibinding

被刻印的时光 ゝ 提交于 2019-11-29 07:12:13
I have this use case that is very similar to the robot-legs example of Guice, except I don't know how many "legs" I have. Therefore I can't use the annotations needed for the robot-legs example. I expect to gather all these "legs" in an java.util.Set with Guice's Multibindings extension. Technically, in a PrivateModule I would like to expose an implementation directly as an element of the set that will be provided by the Multibindings extension. I just don't know how to do that. For reference and code example, see the robot-legs example here: http://code.google.com/p/google-guice/wiki