Guice

Current Request/User details in Models in Scala Play! 2.5

喜欢而已 提交于 2019-12-11 13:39:46
问题 I would like to have access to the current user somewhere deep in my models of my Play app, for things like setting the author, checking that the user can actually save this type, etc. Ideally, what I would like to use is Guice's @RequestScoped to inject the same UserIdentity across my request, wherever I need it. However, as far as I can tell, the Play! Framework only supports @Singleton and no-scope. So either we'd get the same UserIdentity injected across requests or a different one for

Does Guice binding bind subclass as well?

耗尽温柔 提交于 2019-12-11 13:39:39
问题 So I have a module which binds an Interface with an implementation class. bind(ILocalStore.class).to(LocalStore.class); Will this binding also inject the following constructor: @Inject public LocalStoreUser(LocalStore localstore) { this.localstore = localstore } 回答1: The injection will work, but not because of the binding. Guice treats lookups as if they were a simple Map<Key, Provider> lookup, where Key is composed of a (binding annotation, parameterized type) pair. Guice will not

Guice multibindings package missing in imports

筅森魡賤 提交于 2019-12-11 13:34:08
问题 I have acquired the google.inject package via ivy in my IDE, however, I dont see the pacakage com.google.inject.multibindings.Multibinder Which is referenced here http://google-guice.googlecode.com/svn/trunk/latest-javadoc/com/google/inject/multibindings/Multibinder.html I'm wondering --- maybe there are multiple guice repost which I should pull from ? I do, however, see the following packages : com.google.inject -> binder/internal/matcher/util My ivy definition : <dependency org="com.google

Is Sitebricks compatible with GAE backends (Java)

我们两清 提交于 2019-12-11 12:47:52
问题 I would like to know whether it is possible to host a Google App Engine backend servlet using Sitebricks. I am trying to do so in my GAE Java app -- frontend gets the backend URL using GAE's BackendService interface and send an HTTP Request -- but the HTTP response always returns with a 404 Not Found ). I would love to post some source code / configuration files, but I fell that it may be best for me to explain what I am doing. Basically, my servlet has been configured using Sitebricks in the

Artifact is pulled without explicit dependency shown by sbt-dependency-graph

北战南征 提交于 2019-12-11 09:54:29
问题 My almost-empty SBT project here has only one dependency: "org.apache.hadoop" % "hadoop-yarn-server-nodemanager" % "2.2.0" Checking the pom of such artifact, it seems it does not depend on any guice-servlet artifact. However when I run sbt dependency-tree I see something different, it does depend on a guice-servlet artifact: user@laptop:~/workspace/pack$ sbt dependency-tree [info] Loading project definition from /home/user/workspace/pack/project [info] Set current project to pack (in build

Have a common provider for subclasses using Guice?

核能气质少年 提交于 2019-12-11 09:31:23
问题 I am trying to implement a common provider for all the subclasses, imagine some schema: SuperComponent.class is the parent of ComponentA.class and ComponentB.class . I have the provider: @Provides <T extends SuperComponent> List<T> providesComponents(Provider<T> provider) { List<T> componentList = new ArrayList<>(); for (int i = 0; i < 5; i++) { componentList.add(provider.get()); } return componentList; } The idea is to call this provider when is required the objects List<ComponentA> and/or

'idle in transaction' when using Hibernate, Postgres and Guice Provider

我的未来我决定 提交于 2019-12-11 09:11:55
问题 When I execute: select * from pg_stat_activity where state ~ 'idle in transact' I get inappropriate number of rows with state 'idle in transaction'. Some of them idle for a few days. Most of them, are the same simple select query which are executed from one service class (Hibernate 5.1.0.Final, Guice 4.1.0): public class FirebaseServiceImpl implements FirebaseService { @Inject private Provider<FirebaseKeyDAO> firebaseKeyDAO; @Override public void sendNotification(User recipient) { List

How to implement a new guice scope that caches and return named instances?

纵饮孤独 提交于 2019-12-11 08:56:19
问题 I want to be able to connect to various back-ends by changing a custom header of my HTTP requests. Therefore I want that my request is served with a controller instance that is specific to the selected back-end. The controllers that serve the requests are created using Guice and have many dependencies. I want to cache these controller instances. So for each (SomeController.class, backend) pair there would be a cached instance. How to implement such a Guice scope? I am using Play Framework 2.1

Provider<HttpSession> not getting injected

China☆狼群 提交于 2019-12-11 08:25:06
问题 I am using gwt dispatch to communicate and get data from server to client. In order to get user specific data I want to store the user object in httpsession and access application specific data from servlet context but when I inject Provider<HttpSession> when the handler execute is called but the dispatchservlet the provider is null i.e it does not get injected. following is the code from my action handler @Inject Provider<HttpSession> provider; public ReadEntityHandler() { } @Override public

Is it possible to bind dependencies to interceptor in TestNG?

随声附和 提交于 2019-12-11 07:16:51
问题 public class AbstractTest implements ITestListener { @Inject protected MobConfiguration mob; @Override public void onStart(ITestContext context) { // TODO Auto-generated method stub } } When i tried to inject dependencies in listener class, it always returns null? Is there any possible ways to handle DI in listener or interceptor implementer class? 回答1: I have successfully tried this approach (using a factory, code example at the end of this answer). There is one addition to care for, if you