New issue 82 by andres.a.testi: Add support for toInstance() injections
http://code.google.com/p/google-gin/issues/detail?id=82
Add support for toInstance() injections.
Proposed Solution: Add lite runtime emulation in the package
com.google.inject.client.impl, implementing the Ginjector interface to
store the instances being injected, and invoke the GinModule.configure()
methods. Each instance should be bound as EAGER_SINGLETON. If no runtime
support is needed, the generated code should be the same as classic GIN.
There are two possible implementations to store the instances:
-1 Indexed by order of injection (array of instances):
Instances are stored in an array in the same order that are injected. A
ToInstanceBinding, generates a creator method that returns the instance by
index:
* toInstance() implementation:
void toInstance(T instance){
instances[instanceCount++] = instance;
}
* creator:
private Foo create_foo(){
return instances[10];
}
PRO: Good performance, could be optimized by enhanced constant folding and
propagation.
CON: Order of injection is not deterministic.
-2 Indexed by Key.toString() ( Map<String, Object> ): This adds a more
complex runtime support, where each TypeLiteral.toString() must be emulated
in runtime to enable Key.toString() for indexation of toInstance():
* toInstance() implementation:
void toInstance(T instance){
instances.put(key.toString());
}
* creator:
private Foo create_foo(){
return instances.get("Key[type=com.google.gwt.inject.client.test.Foo,
annotation=[none]]");
}
PRO: Deterministic injection.
CON: Performance impact, mantaining maps and support Key.toString()
A patch for the solution 1 is attached.
Attachments:
gin-indexedToInstance-patch.diff 32.5 KB
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
Comment #1 on issue 82 by aragos: Add support for toInstance() injections
http://code.google.com/p/google-gin/issues/detail?id=82
Thanks for writing this patch! I'll try to do the code review soon and will
leave
some comments there.
Comment #2 on issue 82 by aragos: Add support for toInstance() injections
http://code.google.com/p/google-gin/issues/detail?id=82
Since the review doesn't seem to go anywhere right now, I'll set this back
to "accepted" until we come up with a working idea. :)