guice

How to integrate Hessian with Guice?

We're looking at technologies for an up and coming project here and I really want to use Guice as our dependency injection framework, I also want to use Hessian for client/server comms, but it doesn't seem to be compatible with Guice. public class WebMobule extends ServletModule { @Override protected void configureServlets() { ser...

is guice-struts2-plugin-2.0 support the Struts 2.x ???

Hi all, I am using Guice 2.0 and its struts plugin 'guice-struts2-plugin-2.0' in my application. The struts version is 'Struts2-core-2.1.8.1 and application server is Jboss 4.2.2. when deploying application getting problem java.lang.NullPointerException : at com.google.inject.struts2.GuiceObjectFactory $ProvidedInterceptor.destroy(Gu...

how to inject resource with guice

I have a class, being injected by guice and this class constructor invokes super, with resource loaded by class.getResource(..) @SuppressWarnings("serial") public class CleanAction extends AbstractAction { private final JTable table; private final PowderTableModel tableModel; @Inject public CleanAction(@Named("data") J...

Best way to swap Guice bindings based on command line parameter

I have a Java main application with somewhat complex command line arguments. These arguments are currently processed by a CommandLineArgumentProcessor class. Here's what my code current looks like: public static void main(String[] args) { Injector injector = Guice.createInjector(new ConfigModule(), new WorkModule(), new ReportModul...

Inject key into MapBinder

I am trying to inject a Map into a class using Guice where the map has the form Map<MyInterface, Integer>. I want to use the MapBinder extention to accomplish this, but it seems that MapBinder requires an instantiated object for the key. I would like to have Guice inject instantiations of the key, since they are complex objects that re...

Guice generics - how can I make it less ugly?

I have an interface Producer<T> and a concrete FooProducer that implements Producer<Foo>. Binding this in guice looks ugly as sin: bind(new TypeLiteral<Producer<Foo>>() {}).to(FooProducer.class); I have lots of these such bindings. I have tried the following: static <T> TypeLiteral<Producer<T>> producer() { return new TypeLiteral...

Injecting a generic factory in Guice

The following code is an example of a factory that produces a Bar<T> given a Foo<T>. The factory doesn't care what T is: for any type T, it can make a Bar<T> from a Foo<T>. import com.google.inject.*; import com.google.inject.assistedinject.*; class Foo<T> { public void flip(T x) { System.out.println("flip: " + x); } } interface Ba...

Scala and Annotation

Just thinking of implementing Guice in scala Any sample code ? ...

using Google Guice GraphViz extension and private modules.

Hi, I have simple private module: public class SomePrivateModule extends PrivateModule { @Override protected void configure() { bind(SomeInterface.class). annotatedWith(SomeAnotation.class). to(SomeClass.class); expose(SomeInterface.class).annotatedWith(SomeAnotation.class); bind(S...

Using Guice without a main method

Hi, I'm creating a library that will be included as a jar, so it won't contain a main method. I'm wondering what is the best practice for bootstrapping Guice in this case. I have one top level singleton. public class TestManager { private TestManager() { } public static TestManager getInstance() { // cons...

Get multiple new instances with 0 coupling to Guice

I created a class that uses the the Java Executor API to create/manage a pool with fixed number of threads. Each thread needs a new instance of a particular object, and I would like to inject this object with Guice. For the moment I'm using a Provider which provides new instances of the object through its get() method. But now this clas...

"Please wait until after injection has completed to use this object" error from Guice

We have two singleton objects (declared via in(Scopes.SINGLETON)) in Guice that each uses the other in its constructor. Guice's way to implement this is with proxies - it initializes the object at first with a proxy to the other object, and only when that object is needed it is resolved. When running this code from several threads, we g...

Google GIN AbstractGinModule & GWT.Create()

Hi, I have a class that extends AbstractGinModule like: public class ClientModule extends AbstractGinModule { public ClientModule() { } @Override protected void configure() { ... ... bind(...class).annotatedWith(...).to(...class).in(Singleton.class); ... } } The idea that I have is to bind one class with ano...

unable to find com.sun.grizzly.tcp.http11.GrizzlyAdapter.setResourcesContextPath(String)

I trying to expose some groovy service with jersey and girzzly. but i got a wierd error when i'm launching my servlet container. Here is the snippet which lauch it: ServletAdapter adapter = new ServletAdapter(); Injector injector = Guice.createInjector(new GmediaModule()); GuiceContainer container = new GuiceContainer(injector); adapte...

Shutdown Quartz sheduler

I have Quartz scheduler in my web application with Guice. I followed code found here. Everything works fine, but I can't figure out how to shutdown scheduler. My context listener looks like this: public class MyAppContextListener extends GuiceServletContextListener{ @Override protected Injector getInjector() { return Gu...

GWT gwt i18n Gin Module

Hello :-) My question is the following: I got one application running with GWT. At the startup of the application, one GWTClientModule which extends AbstractGinModule or another GWTClientModule is loaded. Based on that switch I would like to set the local. Is there a way to set the local not directly in .html by doing as follow: <me...

How do I reconstruct generic type information for classes given a TypeLiteral?

I have the following problem: Given a Guice type literal TypeLiteral<T> template and a class Class c implementing or extending T, construct a type Type t which is equivalent to c with all type variables instantiated so as to be compatible with template. If c has no type variables, it's easy; c is the type in question. However, if ...

How to avoid having injector.createInstance() all over the place when using guice?

There's something I just don't get about guice: According to what I've read so far, I'm supposed to use the Injector only in my bootstrapping class (in a standalone application this would typically be in the main() method), like in the example below (taken from the guice documentation): public static void main(String[] args) { /* ...

What is the latest official version of Google Guice and where should I get it from?

I downloaded the guice 2.0 source from http://code.google.com/p/google-guice/downloads/list but when I looked at the pom I saw the version was was marked as 1.0-RC2 and the target jar that was build by maven was named guice-1.0-RC2.jar. On the central maven repository under com.google.inject there is a jar named guice-2.0.jar. Under com....

Guice wrap generic injections

Is it possible to wrap generic injections in some way? Given the interface: interface IFoo<T> In my guice module: bind((Key<IFoo<SomeType>) Key.get(Types.newParameterizedType(IFoo.class, SomeType.class))).to(Foo.class); But before I return the Foo instance I want to wrap it with this: class FooWrapper<T> implements IFoo<T> { public...