Guice

How to bind with provider which uses annotation value in Guice?

﹥>﹥吖頭↗ 提交于 2019-12-01 09:41:48
问题 Is there any way to bind with provider which interprets target's annotation value in Google Guice? Example: bind(Resource.class) .annotatedWith(MyAnnotation.class) .toProvider(new MyProvider<MyAnnotation, Resource>{ public Resource get(MyAnnotation anno){ return resolveResourceByAnnoValue(anno.value()); } }); I want to initialize field of an Android Activity class by annotated binding. It should have to take multiple resources by it's unique Id. Original Way: public class TestActivity extends

Google Guice on Google Appengine: mapping with working _ah

爷,独闯天下 提交于 2019-12-01 08:56:43
I have a Google Appengine/Guice/Wicket Application. My problem is that due to the mapping I can't access the /_ah/admin Page anymore. My Servlet Module says: serve( "/*" ).with( WicketServlet.class, getWicketServletParams() ); so far it is more or less expected that accessing /_ah/admin gives a 404. I problem is that I don't find a workaround. I tried different combinations of serveRegex(), but even serveRegex( "/.*" ).with( WicketServlet.class, getWicketServletParams() ); leads to problems, as the URL dispatching of Wicket gets broken. The application keeps on repeating the Path (e.g. /list

Guice inject single instance into multiple objects without using @Singleton

流过昼夜 提交于 2019-12-01 06:44:29
I was reading the Guice documentation, and came across a section labeled Eliminate the Cycle (Recommended) which peaked my interest because it's exactly the issue that led me to the documentation today. Basically, to eliminate cyclic dependencies, you "extract the Dependency Case into a separate class." Okay, nothing new there. So, in the example, we have. public class Store { private final Boss boss; private final CustomerLine line; //... @Inject public Store(Boss boss, CustomerLine line) { this.boss = boss; this.line = line; //... } public void incomingCustomer(Customer customer) { line.add

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 to initialize a circular dependency (final fields referencing each other)?

跟風遠走 提交于 2019-12-01 05:24:28
How do you initialize this: class A { final B b; A(B b) { this.b = b; } } class B { final A a; B(A a) { this.a = a; } } DI framework, reflection, better design? Motivation and a use case (added) : My particular use case is simplifying field access in A 's and B 's sub-classes. So I'm injecting them to shortly reference them by fields in the derived classes without a need to declare explicitly in each sub-class. There is also a recommendation on DI that objects should better be immutable: Guice best practices and anti-patterns . You could use a factory method class A { final B b; A(B b) { this

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); } })

using guice injection with actor throws null pointer

大兔子大兔子 提交于 2019-12-01 04:49:44
I'm getting null pointer exception on the field injection of a server which is started as an akka actor. Schedular part: private ActorRef myActor = Akka.system().actorOf( new Props(Retreiver.class)); @Override public void onStart(Application app) { log.info("Starting schedular.....!"); Akka.system() .scheduler() .schedule(Duration.create(0, TimeUnit.MILLISECONDS), Duration.create(30, TimeUnit.MINUTES), myActor, "tick", Akka.system().dispatcher()); } Retreiver class part: public class Retreiver extends UntypedActor { private Logger.ALogger log = Logger.of(Retreiver .class); @Inject private

How to use Guice in Swing application

旧时模样 提交于 2019-12-01 04:20:51
I have a Swing application that I would like to convert from spaghetti to using dependency injection with Guice. Using Guice to provide services like configuration and task queues is going great but I'm now starting on the GUI of the app and am unsure of how to proceed. The application is basically a JFrame with a bunch of tabs in a JTabbedPane . Each of the tabs is a separate JPanel subclass that lays out the various components and needs services to perform actions when certain buttons are pressed. In the current application, this looks somewhat like this: @Inject public MainFrame(SomeService

Guice inject single instance into multiple objects without using @Singleton

戏子无情 提交于 2019-12-01 04:11:29
问题 I was reading the Guice documentation, and came across a section labeled Eliminate the Cycle (Recommended) which peaked my interest because it's exactly the issue that led me to the documentation today. Basically, to eliminate cyclic dependencies, you "extract the Dependency Case into a separate class." Okay, nothing new there. So, in the example, we have. public class Store { private final Boss boss; private final CustomerLine line; //... @Inject public Store(Boss boss, CustomerLine line) {

CXF and Google Guice using JAX-RS + JAX-WS

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 04:09:56
I would like to integrate CXF with Google Guice. I am already using Guice in my project and I want to avoid adding extra dependencies. CXF was my choice because one of the requirements is to be able to provide XML, JSON, JSONP and SOAP interface to the users of the services without having duplicate code (right now we have SOAP-specific classes, for XML we use Struts and for JSON we wrote our own parsers, I know, I feel dirty too). Anyway, afaik , CXF can fulfill this requirement, so it seems I'm stuck with CXF. Any ideas or pointers or advice on how to integrate Guice with CXF? I thought of