Guice

Guice creates Swing components outside of UI thread problem?

霸气de小男生 提交于 2019-11-30 22:20:27
I'm working on Java Swing application with Google Guice as an IOC container. Things are working pretty well. There are some UI problems. When a standard L&F is replaced with Pushing pixels Substance L&F application is not running due to Guice's Swing components creation outside of UI thread. Is there a way to tell Guice to create Swing components in the UI thread? Maybe I should create custom providers which will return Swing components after SwingUtilities.invokeAndWait(Runnable) creates them. I don't like the idea of running the whole application in UI thread, but maybe it's just a perfect

Guice : How to bind classes that are dynamically obtained by an already binded object?

馋奶兔 提交于 2019-11-30 21:48:51
I'm developing a small web framework using Guice. I have a Router object that, once initialized, expose a getControllerClasses() method. I have to loop over all those dynamically returned classes to bind() them using Guice. I bind the Router : bind(IRouter.class).to(Router.class); But then, how can I obtain the binded Router instance, in a Module, so I can also bind the classes returned by its getControllerClasses() method? The only way I've been able to get the Router instance in a Module, is by binding this instance in a first module and then injecting it in a second module, using @Inject on

Guice don't inject to Jersey's resources

让人想犯罪 __ 提交于 2019-11-30 20:16:57
问题 Parsed allover the whole internet, but can't figure out why this happens. I've got a simplest possible project (over jersey-quickstart-grizzly2 archetype) with one Jersey resource. I'm using Guice as DI because CDI doesn't want to work with Jersey either. The problem is that Guice can't resolve the class to use when injecting in Jersey's resources. It works great outside, but not with Jersey. Here is the Jersey resource: import com.google.inject.Inject; import javax.ws.rs.GET; import javax.ws

Guice , afterPropertiesSet

纵饮孤独 提交于 2019-11-30 19:23:58
问题 Someone knows some way that how can I achieve the same functionality in Guice as the 'afterPropertiesSet' interface in spring ? ( its a post construction hook ) 回答1: By far the simplest solution, if you're using constructor injection and not doing anything too crazy, is to create a post-construction method and annotate it with @Inject : final class FooImpl implements Foo { private final Bar bar; @Inject FooImpl(Bar bar) { this.bar = bar; ... } @Inject void init() { // Post-construction code

How to use @Singleton of Guice ?

北慕城南 提交于 2019-11-30 17:49:05
问题 I need to make one instance of some class - and this one instance need to be accessible from any place in the code. So, I found the Guice... and i want to use the '@Singleton' from this package but i don't find any example or some doc to how to use it and how to make the declaration. 回答1: Ok, My answer is not a specific for @Singleton of Guice , But If you want to Make a class which is accessible through all your activities then I think,You have to use Application class of Android. (This is

What is the best pattern for managing multiple versions of the same dependency tree in Guice?

♀尐吖头ヾ 提交于 2019-11-30 15:56:36
问题 I would like to instanciate several versions of the same kind of dependency tree/chain which use different implementations for some of the interfaces in that tree/chain. What is the best Guice practice/pattern to use in such case? Here is a concrete example of my problem. I have a Writer interface which can potentially be a file writer or a std-out writer, which will be situated at the leaf of my dependency hierarchy. Something like this: interface Writer { ... } class FileWriter implements

ClassNotFoundException with Guice 2.0

好久不见. 提交于 2019-11-30 15:34:25
问题 The code below generates an error using Guice 2.0. With Guice 1.0 everything is fine. The JDK is Java 6 update 15. public class App { public static void main(String[] args) { Guice.createInjector(new AbstractModule() { @Override protected void configure() { // just testing } }); } } The error is: Exception in thread "main" java.lang.NoClassDefFoundError: [Lorg/aopalliance/intercept/MethodInterceptor; at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class

What is the best pattern for managing multiple versions of the same dependency tree in Guice?

心已入冬 提交于 2019-11-30 15:16:52
I would like to instanciate several versions of the same kind of dependency tree/chain which use different implementations for some of the interfaces in that tree/chain. What is the best Guice practice/pattern to use in such case? Here is a concrete example of my problem. I have a Writer interface which can potentially be a file writer or a std-out writer, which will be situated at the leaf of my dependency hierarchy. Something like this: interface Writer { ... } class FileWriter implements Writer { ... } class StdOutWriter implements Writer { ... } Another logger interface is used to add a

TypeLiteral injection with reflection

空扰寡人 提交于 2019-11-30 14:55:55
Context : java using guice (last version) Hi everybody, is it possible to inject some TypeLiteral with Guice by this way : public MyClass<?,?> getMyClass(Injector injector, Class<?> a, Class<?> b) { //how to Inject MyClass with type a & b ? //e.g : injector.getInstance(MyClass<"a class","b class">) } public interface MyClass<S,T> { public T do(S s); } public class ClassOne implements MyClass<String,Integer> { public Integer do(String s) { //do something } } Module : bind.(new TypeLiteral<MyClass<String,Integer>(){}).to(ClassOne.class); bind.(new TypeLiteral<MyClass<String,Double>(){}).to

Guice Performance on Android

大憨熊 提交于 2019-11-30 14:38:31
问题 As a Java developer I've become accustomed to having dependency injection available in applications. For Android though, I am especially wary of performance. What are the performance implications for using Guice in an Android app? I assume there is some overhead, but is it significant enough that I should avoid using Guice? My use of it would likely just be to inject a few shared objects into various activities. 回答1: As of version 3, Guice caches reflective objects to improve performance.