Issue 82 in google-gin: Add support for toInstance() injections

20 views
Skip to first unread message

googl...@googlecode.com

unread,
Feb 21, 2010, 10:08:54 AM2/21/10
to googl...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

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

googl...@googlecode.com

unread,
Feb 24, 2010, 1:22:17 PM2/24/10
to googl...@googlegroups.com
Updates:
Status: Review
Owner: aragos
Labels: -Type-Defect Type-Enhancement

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.

googl...@googlecode.com

unread,
Jul 7, 2010, 12:16:47 PM7/7/10
to googl...@googlegroups.com
Updates:
Status: Accepted

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. :)

googl...@googlecode.com

unread,
Mar 8, 2015, 3:21:08 AM3/8/15
to googl...@googlegroups.com

Comment #3 on issue 82 by Sebastia...@googlemail.com: Add support for
toInstance() injections
https://code.google.com/p/google-gin/issues/detail?id=82

Hi,
are there any plans to support toInstance() in future? How should this
feature be implemented? I'll try to do the thing if you can give some
hints. The proposed patch seems not to be a valid solution?!

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages