How does lazy instantiation works with jin?
Can I inject a parametrized type to a class using jin?
I tried several approaches but I get error
Sorry for answering a question in the comments but....
@arashbi Lazy instantiation works fine. You can see this by adding some
sort of message, such as Window.alert("XXX"), to the constructor of a class
created by gin. You will see that the message only appears when the
injector.xxx() method is called. By printing out hashCodes you can also
check that Singleton etc. works as you expect.
For parameterized types use the TypeLiteral class, take a look at the Guice
documentation for this.
While working on a gin module in development mode, I often get
the "Deferred binding result type 'A' should not be abstract" error. After
restarting the development console, it's gone. Just a hint in case you run
into this one as well.
Debian, 2.6.26-2
Firefox 3.6.13
GWT 2.1.1
GIN 1.0
I have a question to Gin team:
In Guice, I specify the module when I am creating an injector. This is fine
because I can create two injectors with different modules, for testing
purposes.
In Gin, I must specify the module to use in the Injector interface via
@GinModules. So I cannot create two instances of the injector with
different modules. This creates a dependency from an interface to the
implementation and defeats the whole purpose of dependency injection.
Is there a way around it?
There are two ways to reuse Ginjectors. The classic way is to subclass
them, i.e. if the ginjector with all your methods is A, then have 2 (n)
ginjectors B and C, each of which extend A but which define different gin
modules.
Another way to easily swap the gin module names is to use GWT properties,
which was recently implemented. Take a look at
http://code.google.com/p/google-gin/source/browse/trunk/src/com/google/gwt/inject/client/GinModules.java
for some more documentation.