guice

Guice configuration error

I'm trying to use Google Guice with the @Inject and @Singleton properties as follows: I have: A Module with an empty configure() method. An interface IFoo A class Foo (implementing IFoo), annotated with @Singleton, with a parameter-less constructor annotated with @Inject. This is the single annotated constructor. The classes, constr...

Guice Custom Scopes and Spring managed beans

(x-posted to guice mailing list) I'm trialling Guice on a new library that will live in an existing application. All our apps right now are spring apps and we have some common code that is tied to spring, mainly to do with the thread model we tend to use. It basically gives us (what could be seen as) a logical thread. So we can throw j...

Guice SPI: find bindings by wildcard types

Guice provides a means to find all bindings for a given type (Injector#findBindingsByType) and it also provides a TypeLiteral class from which it seems possible to construct a wildcard type. What I would like to do is find all bindings for some type that is parameterised by a wildcard type but I can't figure out how to do it. A look at t...

Reconstructing generic types at runtime with Guice via Types and TypeLiterals

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 parameterised type of Foo. s...

Getting to Guice created objects from dumb data objects

I've taken the plunge and used Guice for my latest project. Overall impressions are good, but I've hit an issue that I can't quite get my head around. Background: It's a Java6 application that accepts commands over a network, parses those commands, and then uses them to modify some internal data structures. It's a simulator for some har...

Guice: Varying the type injected according to how the owner has been injected

I have a guice based app that now needs multiple instances of a given type so I plan on using a named annotation to disambiguate the dependencies. However a dependency of this type also needs to vary based on which one I get. To illustrate lets say I have @Singleton public class FooCache { private final FooCacheListener listener; ...

Getting multiple guice singletons of the same type

can you get 2 singleton instances of the same underlying type? this is obviously trivial in spring as it is based on named instances to which you attach a scope but I can't see the equivalent in guice which is about binding types to implementation classes. Note that I don't want to have to bind to the instance as the instances in quest...

Converting from Waffle/Pico to Struts2/Guice

Hi all, I've been tasked with converting an application which was developed by myself in the Waffle Framework using PicoContainer as a DI mechanism into our new "stack" which is to use Struts2 as a framework with Guice as the DI mechanism. Does anyone out there have any helpful pointers as to how to do this with minimal pain and at the...

ClassNotFoundException with Guice 2.0

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 erro...

google gin? use with spring?

i know gin is client side of guice . so in order to use gin. it must be used together with guice? i wonder, can it be used with spring? ...

How do I define dynamic and just-in-time bindings with Guice?

I am trying to use Guice for a test framework based on TestNG. This frameworks analyzes the test class for dependencies and provides them eliminating the need to build them in tests. Guice is all about injection and I think is a good fit for the framework. But the question is how do I define bindings after I have created the injector? T...

Injecting an object into a HttpSessionAttributeListener via Guice ?

Configuration: Guice 1.0, Apache Tomcat 6.0 I am currently manually injecting objects configured in a Guice Module, into my servlet, using this method: public void init( ServletConfig config ) throws ServletException { super.init( config ); ServletContext sc = config.getServletContext(); Injector injector = (Injector) sc ...

Guice-style service locator

Has anybody ever seen/attempted to write a service locator pattern which uses a Guice style configuration system? Currently I have a GWT project (which happens to use GWT-RPC) that uses a command pattern wherein my RPC servlet that looks like this... public interface TransactionService extends RemoteService { <T extends Response> ...

Can anyone provide a clear explanation of why Google Guice is useful?

I've read about Google Guice, and understand the general issues with other approaches to dependency injection, however I haven't yet seen an example of someone using Guice "in practice" where its value becomes clear. I'm wondering if anyone is aware of any such examples? ...

Should I use Spring or Guice for a Tomcat/Wicket/Hibernate project?

I'm building a new web application that uses Linux, Apache, Tomcat, Wicket, JPA/Hibernate, and MySQL. My primary need is Dependency Injection, which both Spring and Guice can do well. I think I need transaction support that would come with Spring and JTA but I'm not sure. The site will probably have about 20 pages and I'm not expect hug...

Solutions to organize Guice binding configurations

It's apparently a bad idea to put all bindings in one module, so what do you think is the more elegant way? I think Bob's idea could be good start for this discussion: It's hard to come up with one-size-fits-all rules for this sort of thing, but one Module per package is certainly a good place to start. Putting a Module in each pack...

Using Guice with circular dependencies

Consider this simple example. Class A { B b; A() { this.b = new B(this); } } In this example instance A knows about instance B, and instance B knows about instance A. My question is: how to instantiate instance A with Guice, i.e. how to make Guice take care of this complex circle dependencies? ...

Instanciate an injector with multiple AbstractGinModule

In google Guice, I can create an injector based on multiple module with the function createInjector. Because I use GWT.create to instanciate the injector in GoogleGin, is it possible to create a Ginjector based on multiple AbstractGinModule. If we can't, how do you organize your code to avoid having all your binding in the same Module ...

How to bind String to variable in Guice?

I'm new to Guice and here is a naive question. I learned that we could bind String to a particular value through: bind(String.class) .annotatedWith(Names.named("JDBC URL")) .toInstance("jdbc:mysql://localhost/pizza"); But what if I want to bind String to any possible charactors? Or I think it could be desribed this wa...

How to bind Assisted Injected class to interface?

Here is the problem I met: Class SimpleCommand implements Executable{ private final ConfigManager config; private String name; @Inject public SimpleCommand(ConfigManager config, @Assisted String name){ this.config = config; this.name = name; } } Class MyModule extends AbstractModule{ @Override protected void configure() { ...