Guice

Use Guice multibindings with assisted inject for the set members

狂风中的少年 提交于 2021-02-08 08:41:51
问题 I have a class PluginManager which accepts a Set<Plugin> using the Guice multi-bindings feature. However, the PluginManager has some runtime information that needs to be passed to the Plugin constructor. This seems to be a perfect use-case for Guice assisted injection i.e. my PluginManager would have Set<PluginFactory> injected, where the runtime information is provided to each factory, resulting in the required Plugin instances. I don't know the syntax to use in the Module however. The

Play Framework Java: Mock using Mockito: Wanted but not invoked, Actually, there were zero interactions with this mock

ぐ巨炮叔叔 提交于 2021-02-04 08:36:09
问题 I am new to Mockito and Play Framework, so can anyone suggest a solution for this: I have 3 classes as follows: I have a Play application where I am calling a helper method, which indeed calls an ApiClient, which calls an external api and fetches the results and returns CompletionStage of that result. And the helper method indeed returns the same result to the controller. The Code is as follows. public class MyController extends Controller{ @Inject WSClient wsClient; MyControllerHelper

Google Guice - how to automatically add binding

心已入冬 提交于 2021-01-29 00:11:53
问题 In my project I am using Google Guice for dependency injection. In my Module class which extends Google Guice's AbstactModule I have a MapBinder, where the key is a name of an item and the value is an implementation of my Item interface (e.g. FirstItem). MapBinder<String, Item> itemMapBinder = MapBinder.newMapBinder(binder(), String.class, Item.class); itemMapBinder.addBinding("FirstItem").to(FirstItem.class); Currently every time I add new implementation of Item (e.g. SecondItem) I also have

Google Guice - how to automatically add binding

ε祈祈猫儿з 提交于 2021-01-29 00:09:43
问题 In my project I am using Google Guice for dependency injection. In my Module class which extends Google Guice's AbstactModule I have a MapBinder, where the key is a name of an item and the value is an implementation of my Item interface (e.g. FirstItem). MapBinder<String, Item> itemMapBinder = MapBinder.newMapBinder(binder(), String.class, Item.class); itemMapBinder.addBinding("FirstItem").to(FirstItem.class); Currently every time I add new implementation of Item (e.g. SecondItem) I also have

Google Guice - how to automatically add binding

你离开我真会死。 提交于 2021-01-29 00:09:04
问题 In my project I am using Google Guice for dependency injection. In my Module class which extends Google Guice's AbstactModule I have a MapBinder, where the key is a name of an item and the value is an implementation of my Item interface (e.g. FirstItem). MapBinder<String, Item> itemMapBinder = MapBinder.newMapBinder(binder(), String.class, Item.class); itemMapBinder.addBinding("FirstItem").to(FirstItem.class); Currently every time I add new implementation of Item (e.g. SecondItem) I also have

Google Guice - how to automatically add binding

血红的双手。 提交于 2021-01-29 00:05:14
问题 In my project I am using Google Guice for dependency injection. In my Module class which extends Google Guice's AbstactModule I have a MapBinder, where the key is a name of an item and the value is an implementation of my Item interface (e.g. FirstItem). MapBinder<String, Item> itemMapBinder = MapBinder.newMapBinder(binder(), String.class, Item.class); itemMapBinder.addBinding("FirstItem").to(FirstItem.class); Currently every time I add new implementation of Item (e.g. SecondItem) I also have

Google Guice - how to automatically add binding

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 00:03:22
问题 In my project I am using Google Guice for dependency injection. In my Module class which extends Google Guice's AbstactModule I have a MapBinder, where the key is a name of an item and the value is an implementation of my Item interface (e.g. FirstItem). MapBinder<String, Item> itemMapBinder = MapBinder.newMapBinder(binder(), String.class, Item.class); itemMapBinder.addBinding("FirstItem").to(FirstItem.class); Currently every time I add new implementation of Item (e.g. SecondItem) I also have

Inheriting annotation for AOP in GUICE

痴心易碎 提交于 2021-01-28 13:36:35
问题 I'm using Guice and AspectJ, and I am trying to do some AOP to measure the execution time of certain methods. I have this annotation which will be used to annotate all the methods I need to measure: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Inherited public @interface MyStopWatch { } I have this method interceptor: public class MyInterceptor implements org.aopalliance.intercept.MethodInterceptor { private final Logger logger = LoggerFactory.getLogger(MyInterceptor.class

Inheriting annotation for AOP in GUICE

扶醉桌前 提交于 2021-01-28 13:34:22
问题 I'm using Guice and AspectJ, and I am trying to do some AOP to measure the execution time of certain methods. I have this annotation which will be used to annotate all the methods I need to measure: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Inherited public @interface MyStopWatch { } I have this method interceptor: public class MyInterceptor implements org.aopalliance.intercept.MethodInterceptor { private final Logger logger = LoggerFactory.getLogger(MyInterceptor.class

Binding a value to one of two possibilities in Guice

被刻印的时光 ゝ 提交于 2021-01-28 12:03:28
问题 Suppose I have a value for which I have a default, which can be overridden if System.getProperty("foo") is set. I have one module for which I have bindConstant().annotatedWith(Names.named("Default foo")).to(defaultValue); I'm wondering what the best way of implementing a module for which I want to bind something annotated with "foo" to System.getProperty("foo") , or, if it does not exist, the "Default foo" binding. I've thought of a simple module like so: public class SimpleIfBlockModule