Guice

How can I access request in Play Guice Module?

十年热恋 提交于 2020-01-24 09:10:08
问题 I am writing an application which handles multiple systems. The user can choose the system which he wants to work with and I store that system ID in session (client session) Now I have Service classes, lets say CustomerService. class CustomerService(val systemID: String) { // Implementation } I want to use Guice to inject the Customer instance to the Controllers. But I want to instantiate the CustomerService with SystemID which is stored in the session. How can I access request.session in

How can I access request in Play Guice Module?

瘦欲@ 提交于 2020-01-24 09:10:06
问题 I am writing an application which handles multiple systems. The user can choose the system which he wants to work with and I store that system ID in session (client session) Now I have Service classes, lets say CustomerService. class CustomerService(val systemID: String) { // Implementation } I want to use Guice to inject the Customer instance to the Controllers. But I want to instantiate the CustomerService with SystemID which is stored in the session. How can I access request.session in

Should i inject Objects needed for execution of an algorithm? Should i inject everything?

百般思念 提交于 2020-01-24 05:10:29
问题 Maybe i missed it in the documentation but i'm wondering how i should handle "helper Objects"? code example: public Path dijkstra(Node startNode, Node endNode) { Set<Node> nodesToInspect = new HashSet<Node>(); // should this Object be injected? Path path = new Path(); // and this one? while (!nodesToInspect.isEmpty()) { // some logic like: path.add(currentNode); } return path; } Should i inject everything or should i say at some point that the algorithm "knows" best what it needs? Should i

How to @Inject a HttpSession object in a service layer (DAO) class in GWT using Guice?

烂漫一生 提交于 2020-01-23 03:50:46
问题 I have such a dirty code in my GWT app, some of the classes of my service layer depend on an HttpSession object. So for example, in one of my DAO (which was a GWT-RPC endpoint) I have something like this : public class MyExampleDAO extends RemoteServiceServlet { public findItems() { // here I need to get the object session to retrieve the currently logged in user in order to query for all its items... } } The problem is that, I am currently migrating the code to use RequestFactory. My DAO

Deferred binding failed

谁都会走 提交于 2020-01-21 09:10:22
问题 My application is throwing: java.lang.RuntimeException: Deferred binding failed for 'com.mygwtapp.client.gin.ClientAppGinjector' (did you forget to inherit a required module?) on this code inside the EntryPoint: private final ClientAppGinjector injector = GWT.create(ClientAppGinjector.class); What could be the problem? Here's the full error Log: java.lang.RuntimeException: Deferred binding failed for 'com.mygwtapp.client.gin.ClientAppGinjector' (did you forget to inherit a required module?)

Can I use some kind of assisted Inject with Dagger?

99封情书 提交于 2020-01-19 04:11:05
问题 With Google Guice or Gin I can specify parameter with are not controlled by the dependency injection framework: class SomeEditor { @Inject public SomeEditor(SomeClassA a, @Assisted("stage") SomeClassB b) { } } The assisted parameter stage is specified at the time an instance of SomeEditor is created. The instance of SomeClassA is taken from the object graph and the instance of SomeClassB is taken from the caller at runtime. Is there a similar way of doing this in Dagger? 回答1: Because

Can I use some kind of assisted Inject with Dagger?

喜你入骨 提交于 2020-01-19 04:10:37
问题 With Google Guice or Gin I can specify parameter with are not controlled by the dependency injection framework: class SomeEditor { @Inject public SomeEditor(SomeClassA a, @Assisted("stage") SomeClassB b) { } } The assisted parameter stage is specified at the time an instance of SomeEditor is created. The instance of SomeClassA is taken from the object graph and the instance of SomeClassB is taken from the caller at runtime. Is there a similar way of doing this in Dagger? 回答1: Because

Guice call init method after instantinating an object

依然范特西╮ 提交于 2020-01-18 13:36:46
问题 Is it possible to tell Guice to call some method (i.e. init()) after instantinating an object of given type? I look for functionality similar to @PostConstruct annotation in EJB 3. 回答1: Actually, it is possible. You need to define a TypeListener to get the functionality going. Something along the lines of the following in your module definition: bindListener(Matchers.subclassesOf(MyInitClass.class), new TypeListener() { @Override public <I> void hear(final TypeLiteral<I> typeLiteral,

Binding a constructor argument based on the Annotation of the class

被刻印的时光 ゝ 提交于 2020-01-17 05:14:20
问题 I have an interface: InterfaceA . I have a class: ConcreteA . I also have two annotations: @AnnotA and @AnnotB . I have done the following bindings: bind(InterfaceA).annotatedWith(AnnotA).to(ConcreteA); bind(InterfaceA).annotatedWith(AnnotB).to(ConcreteA); Next, class ConcreteA has a constructor that takes a String argument called hostName . class ConcreteA { @Inject public ConcreteA(@Named("hostName") hostName) { } ... <rest of class> } I need code to describe the following: If ConcretaA is

JPA 2 + EclipseLink : Caching Issue

只愿长相守 提交于 2020-01-15 10:57:19
问题 I have a strange behavior with caching and JPA Entities (EclipseLink 2.4.1 ) + GUICE PERSIST I will not use caching, nevertheless I get randomly an old instance that has already changed in MySQL database. I have tried the following: Add @ Cacheable (false) to the JPA Entity. Disable Cache properties in the persistence.xml file : <class>MyEntity</class> <shared-cache-mode>NONE</shared-cache-mode> <properties> <property name="eclipselink.cache.shared.default" value="false"/> <property name=