> Looks like a bug in our documentation. As they were designed,
> TypeListeners aren't appropriate for static injection. They are
> intended to expose facilities for per-instance callbacks
> (InjectionListener) and per-instance injections (MembersInjector),
> neither of which is appropriate for static injection.
>
> What did you have in mind?
Ah, that would explain it then. It's certainly unexpected that they wouldn't
work for static injection -- is that a technical limitation?
I've created my own custom injection annotations (@InjectResource) which I use
to inject Android resources into objects. I wasn't able to use the standard
@Inject annotation because android resources are identified with an int
identifier, and there's no way to pass the value of an annotation to a provider
in guice 2.0, at least.
Here's an example:
@InjectResource(R.id.network_error_msg) protected String networkErrorMsg;
Like any other injected objects, these are usually done as non-static members,
but occasionally when dealing with legacy code it is necessary to inject these
values into static fields. So I tried injecting them statically into a legacy
singleton I had, and you know the rest.
>From some conversations on the group it seems like TypeListeners are the
>preferred mechanism to define custom injection mechanisms like the one I
>mention above. As such, it seems like it would be useful for them to also
>support static injection.
Does that sound reasonable?
Cheers,
Mike
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=.