This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
forked from google/guice
-
Notifications
You must be signed in to change notification settings - Fork 1
UntargettedBindings
Sam Berlin edited this page Jul 24, 2014
·
2 revisions
Creating bindings that don't have targets
You may create bindings without specifying a target. This is most useful for concrete classes and types annotated by either @ImplementedBy
or @ProvidedBy
. An untargetted binding informs the injector about a type, so it may prepare dependencies eagerly. Untargetted bindings have no to clause, like so:
bind(MyConcreteClass.class);
bind(AnotherConcreteClass.class).in(Singleton.class);
When specifying binding annotations, you must still add the target binding, even it is the same concrete class. For example:
bind(MyConcreteClass.class)
.annotatedWith(Names.named("foo"))
.to(MyConcreteClass.class);
bind(AnotherConcreteClass.class)
.annotatedWith(Names.named("foo"))
.to(AnotherConcreteClass.class)
.in(Singleton.class);
- User's Guide
- Best Practices
- Frequently Asked Questions
- Integration
- Extensions
- Internals
- Releases
- Community