Guice

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

不问归期 提交于 2019-12-13 06:44:50
问题 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

How do I set up a Google AppEngine webapp with JSF 2.2, JPA 2.0 and Dependency Injection features? [closed]

梦想的初衷 提交于 2019-12-13 06:38:21
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . A couple of weeks ago I was asked to create a web application to run on Google Cloud Platform (SDK v1.9.48 by the time this post was typed in). After configuring AppEngine settings (creating account, project, cloud database, source code repository, etc, etc, etc...), I was ready to develop my first

Building project form multiple subprojects in Eclipse

偶尔善良 提交于 2019-12-13 04:01:46
问题 I have one project that I have modularized using Google Guice. But now when I build subproject I have many steps: 1) Update subproject version number. 2) Pacakage subproject. 3) Update local repository with subproject new version. 4) Update main project pom.xml with subproject newest version number. 5) Update main project dependencies. 6) Run main project as web appliaction, to test changes in subproject. Is it possible to cut down some of these steps to make my development faster? I'm using

Inject @SessionScoped value into filter with Guice

ぃ、小莉子 提交于 2019-12-13 03:43:11
问题 I have a class hold value of a user in session @SessionScoped class UserSession{} Now I have a LoginFilter to ensure some url accessed with user login class LoginFilter{ @Inject UserSession userSession; ... } Then Out of scope exception was thrown when I try to bootstrap jetty. How can I check if the session contains the UserSession object? I don't know the attribute name of UserSession class. 回答1: You can inject a Provider<UserSession> instead of a plain UserSession . 来源: https:/

How to bind a dynamic @Named binding

痴心易碎 提交于 2019-12-13 03:35:32
问题 I'd like to create a configurable Module that will bind a few different @Named things. Applications/injections that use the module will know the @Name ahead of time, but the module itself won't know until it's instantiated at runtime. I'm using kotlin in my example code, but happy for java answers. This fails to compile because all of the @Named annotations need to refer to constant strings, not runtime variables ( An annotation argument must be a compile-time constant ): class DbModule(val

“Error injecting constructor” when mapping Enumeration using Slick 3.1 with play and scala

守給你的承諾、 提交于 2019-12-13 01:35:11
问题 I have the following classes. please note the commented-out Role lines. user model: case class User( uid: Option[Long] = None, // role: Option[Role.Role] = None, firstName: String, lastName: String, middleName: Option[String] = None, email: String, avatarUrl: Option[String], created: DateTime = DateTime.now, modified: DateTime = DateTime.now ) UserComponent and UserDAO: import javax.inject._ import scala.concurrent.Future import org.krazykat.whatsupdoc.models.User import play.api.db.slick.

how to init guice if my running class is junit?

感情迁移 提交于 2019-12-13 01:25:26
问题 I'm writing an API module. while developing I use junit to run the code however eventually some other modules will use my API. I want to use dependency injection pattern a) Where should be my main entry where I init all the dependencies or global utils? b) I thought it be neater using guice injector, but where should I init it? 回答1: It depends on what you're trying to do. I find, with BoundFieldModule and the @Bind annotation in Guice 4.0, that it's generally easiest to just use Guice

TestNG - Accessing ITestContext in Guice Module

时光毁灭记忆、已成空白 提交于 2019-12-13 00:13:31
问题 I was trying to do as per this question. Is there a way to inject ITestContext from TestNg to guice module? Consider this: public class TestParentModule extends AbstractModule { private ITestContext iTestContext; public TestParentModule(ITestContext iTestContext){ this.iTestContext = iTestContext; } @Override protected void configure() { System.out.println("Parent module called"); bind(ITestContext.class).toInstance(iTestContext); } } public class TestModule extends AbstractModule { @Inject

How can I write a generic Guice binding function?

别来无恙 提交于 2019-12-12 21:25:55
问题 How can I abstract the Option type in the below Guice binding code, substituting a generic parameter for Option ? ArrayList<Class<? extends Option>> options = new ArrayList<Class<? extends Option>>(); bindMultibinder(annotation, options); public Key<Set<Option>> bindMultibinder( Named annotation, ArrayList<Class<? extends Option>> contents) { Multibinder<Option> options = Multibinder.newSetBinder(binder(), Option.class, annotation); for (Class<? extends Option> option : contents) { options

Guice cannot find a suitable constructor: @Inject class Patient(v1:C1) {}

半世苍凉 提交于 2019-12-12 20:50:42
问题 How to make it work? I know that short questions aren't appreciated. But I have nothing to add this time. update 1: As workaround I've made the constructor auxiliary, but I don't like this as it adds quite a lot of burden. 回答1: class Patient @Inject() (v1:C1) {} Just found it here: http://www.scala-lang.org/node/3388 来源: https://stackoverflow.com/questions/13434884/guice-cannot-find-a-suitable-constructor-inject-class-patientv1c1