Are you asking if you can somehow have an automatic injection of
Supplier<Foo> the way we special-case injecting Provider<Foo>?
At present, that isn't an automatic thing, the way it is with Provider.
Provider is a core part of dependency injection infrastructure for
Guice, and one is always implicitly there for every binding. That is
not true of Supplier.
However, what you might be looking for is, effectively Assisted Inject,
which is similar, but it won't inherently implement Supplier. You can
make a provides binding that simply binds a Supplier<Foo> to an
anonymous inner implementation assisted-inject factory.. But that's
somewhat manual.
If you are willing to wait a bit, Google is going to release
AutoFactory, which is a very similar system to Assisted-Inject in
concept, but using code-generation. It has a feature slated that would
allow someone to specify an interface like Supplier and it will generate
a factory method (with no parameters) on the generated factory for that
Supplier's only method. I suspect this might meet your needs.
Christian.
On 21 Oct 2013, at 5:32, Romain Gilles wrote:
Hi all,
I would like to know how can I had the same type of feature of
automatic
bindings of Providers (guice or javax-inject) for Suppliers (guave or
java
8)?
I would like to do something like that:
public class MyModule extends AbstractModule {
@Override
protected void configure() {
bind(MyInterface.class).to(MyImpl.class);
}
}
And then be able to indefferently inject it in the following use cases
without extra work:
class MyClient {
private final Provider<MyInterface> myInterfaceProvider;
private final Supplier<MyInterface> myInterfaceSupplier;
@Inject
MyClient(Provider<MyInterface> myInterfaceProvider,
Supplier<MyInterface> myInterfaceSupplier) {
...
}
...
}
Thanks,
Romain.
--
You received this message because you are subscribed to the Google
Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.
Christian Gruber :: Google, Inc. :: Java Core Libraries :: Dependency
Injection
email: [email protected] :::: mobile: +1 (646) 807-9839
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.