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...
(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 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...
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...
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...
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;
...
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...
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...
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...
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?
...
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...
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
...
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> ...
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?
...
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...
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...
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?
...
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 ...
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...
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() {
...