Comment #4 on issue 519 by sberlin: toProvider() should continue to use
Guice's Provider, not JSR-330's
http://code.google.com/p/google-guice/issues/detail?id=519
Sure thing.
Consider a user class with an injectable field:
@Inject javax.inject.Provider<Foo> fooProvider;
If c.g.i.Provider doesn't extend j.i.Provider, then in order to construct
that field, Guice will have to do one of two things:
a) Construct a wrapper j.i.Provider on the fly and inject that, or
b) Change BindingImpl to cache a secondary j.i.Provider (in addition to
c.g.i.Provider).
Neither is show-stopping, but both aren't that great (especially for
platforms like Android, where GC & memory usage matter).
If toProvider required Guice's provider (or if Guice's provider didn't
extend JSR-330s) and a user has a custom javax.inject.Provider, then using
toProvider(Key) or (Class), or (TypeLiteral) will be very strange. Using
toProvider(Provider) requires wrapping the provider using Jsr330.guicify
right now, but I don't think wrapping can be done in the
key/class/typeLiteral case (how do you convert from one to the other?) I
think the only way to make it work would be to
a) Guice will need to add more toProvider(..) methods that take the
j.i.Provider version (and they'll have to be named differently, because the
erasures of the c.g.i.Provider version would conflict), or
b) The user will need to construct their j.i.Provider (can't inject
anything into the constructor) and delegate to it from another
c.g.i.Provider they also will have to construct.
If anything here's wrong, please point it out! I agree it's going to be a
bad thing to have the Provider they're navigated to from toProvider
pointing to the wrong provider, but I'm not sure how else this can be done.
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" 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-dev?hl=en.