Guice

How to use Guice in Swing application

。_饼干妹妹 提交于 2019-12-04 01:15:45
问题 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

Long lasting 'COMMIT' queries with 'idle' state in pg_stat_activity

点点圈 提交于 2019-12-04 00:48:26
If I query: select * from pg_stat_activity where application_name ~ 'example-application'; I get many rows which state is idle and query is COMMIT . They are long lasting and do not disappear. After some time, my application reach hibernate.c3p0.max_size (maximum number of JDBC connections in the pool) limit and stops working with database. Some application implementation details are described in other SO thread: Guice DAO Provider in thread pool - queries become 'idle in transation' Why does it happen? How to solve this problem? If the session is "idle" the query column shows the last

How to access Play Framework 2.4 guice Injector in application?

可紊 提交于 2019-12-04 00:32:38
问题 I want to use the getInstance method of the Guice Injector class in Play Framework 2.4, how can I access it? I have used the Guice FactoryModuleBuilder for implementing a factory that returns another factory at runtime! At the second level of returning a factory I need to access the Play Guice Injector to get objects manually using reflection instead of @Inject annotation. 回答1: There are many ways. I use this one. Edit: This is relevant for Play versions which are <= 2.4: Play

What is the clojure equivalent to google guice?

十年热恋 提交于 2019-12-03 23:56:36
I came across google guice and could not really understand it and what it did, although there seems to be alot of hype around it. I was hoping to get a clojurian perspective of the library and why it is needed/not needed in clojure applications and if there was anything similar built into the language. Because of Java's OO and type system, dynamically switching between different underlying implementations (for test (mocking) purposes for instance) can be difficult to manage. Libraries like Google Guice are intended to handle these dependency injections in Java more gracefully. In Clojure and

guice multibinder with Providers

元气小坏坏 提交于 2019-12-03 22:51:17
问题 I am trying to be able to have this in my code @Inject private Map<String, Provider<Processor>> providers; I was trying but this code does not compile MapBinder<String, Provider<Processor>> mapbinder = MapBinder.newMapBinder(binder, String.class, Provider<Processor>.class); mapbinder.addBinding("splineV1Beta").to(SplineProcessor.class); mapbinder.addBinding("invertV1Beta").to(InvertProcessor.class); This code fails on startup in that it can't bind my Map MapBinder<String,Processor> mapbinder

Reconstructing generic types at runtime with Guice via Types and TypeLiterals

人盡茶涼 提交于 2019-12-03 21:25:57
问题 I have a few types that are like this // a value that is aware of its key type (K) Bar<K> // something that deals with such values and keys Foo<V extends Bar<K>, K> How would one recreate Foo such that you could consume it in Guice? The bit I'm stuck on is how to cross reference the K from Bar to the 2nd parameterized type of Foo. So for example, WildcardType kType = Types.subtypeOf(Object.class); WildcardType barType = Types.subtypeOf(Types.newParameterizedType(Bar.class, pipeKey));

Guice and RequestScoped behaviour in multiple threads

懵懂的女人 提交于 2019-12-03 21:10:18
问题 I am using Guice's RequestScoped and Provider in order to get instances of some classes during a user request. This works fine currently. Now I want to do some job in a background thread, using the same instances created during request. However, when I call Provider.get(), guice returns an error: Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped object. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google

Java Guice DI error: UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl

蹲街弑〆低调 提交于 2019-12-03 18:13:59
问题 I have a simple REST API project using Jersey 2.x. I tried using Google Guice to inject my dependencies, but it doesn't seem to work. I get this error: org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=AccountService,parent=AccountsResource,qualifiers={},position=0,optional=false,self=false,unqualified=null,1658198405) I have this simple resource class @Path("/accounts") @Produces(MediaType.APPLICATION_JSON)

Inject Util Class with Google Guice vs static Methods?

久未见 提交于 2019-12-03 17:39:29
问题 I'm wondering if it is a good style to inject utility methods with google guice. Let's say we have a Converter Utility Class: public class UtilClass { public static Result convert(Source src) { //Do conversion return result; } } My idea is to use guice to inject this Utility as Singleton like this @Singleton public class UtilClass { public Result convert(Source src) { //Do conversion return result; } } Which way is recommended for an Application built with guice? 回答1: It depends on the nature

Builder pattern vs. Dependency Injection (for instance via Guice)

允我心安 提交于 2019-12-03 17:28:14
问题 I'm developing a simple tree-structured database and I'm usually setting dependencies or optional settings via a Builder (Builder pattern). Now I'm not sure when to use for instance Guice, when to use the Builder pattern and when to use a static factory method instead of the constructor itself. I've read Effective Java several times and I think it mentions at least a lot of advantages for not exposing the constructor. It's time to reread ;-) So, do you know of cases which are clearly