frjaeger220 / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Make requestStaticInjection work for TypeListeners #452

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In some situations it's necessary to create custom injection annotations by 
using TypeListeners.

Standard (non-static) injection works fine for members annotated with these 
custom annotations.  However, requestStaticInjection() does not appear to 
work with TypeListeners.  This leads to confusing and unexpected behavior 
for users of these annotations.

It would be nice to if TypeListeners could work as well with static injection 
as 
they do with non-static injection.

http://groups.google.com/group/google-
guice/browse_thread/thread/710b7ecc3ef7e1dd/d032391809fb123a

Original issue reported on code.google.com by mbur...@gmail.com on 9 Dec 2009 at 5:01

GoogleCodeExporter commented 9 years ago
This would help Android developers using guice.

RoboGuice allows developers to inject views and resources into their Android 
applications.  Because some of these objects cannot be determined at injection 
time (such as views, which only exist after setContentView() is called from 
onCreate()), we use a type listener to process a custom injection annotation 
(@InjectView(id) and @InjectResource(id)).

This works great.  However, users expect to be able to access their resources 
statically.  If they try to "@InjectResource(R.string.foo) static String foo", 
they get null because the TypeListener was never called.

I've tried overloading requestStaticInjection in my module to manually invoke 
hear on my type listeners.  This works fine for any bindings that ship with 
RoboGuice, but it doesn't work for bindings that are provided by users in their 
own modules.

There seems to be no technical limitation in the TypeListener interface that 
prevents them from working on static fields.  I've verified that my 
TypeListener injects the static fields properly if I invoke it manually by 
calling injectMembers.  Looking through the Guice code it seems like one would 
just need to loop over the type listeners in InjectionRequestProcessor.

Original comment by mbur...@gmail.com on 27 Jan 2011 at 1:33