mirror of
https://github.com/google/guice.git
synced 2026-10-19 16:16:21 +00:00
Page:
UntargettedBindings
Pages
3rdPartyModules
AOP
AppsThatUseGuice
AssistedInject
Avoid Injecting Closable Resources
AvoidCallingProvideMethodsAndInjectConstructors
AvoidConditionalLogicInModules
AvoidStaticState
BeCarefulAboutIoInProviders
BestPractices
BindingAnnotations
BindingResolution
Bindings
Bootstrap
BoundFields
BuiltInBindings
ClassLoading
CustomInjections
CustomScopes
CyclicDependencies
DocumentPublicBindings
DontReuseAnnotations
Errors
ExtendingGuice
ExtensionSPI
ExternalDocumentation
FrequentlyAskedQuestions
GettingStarted
GoogleAppEngine
Grapher
Guice10
Guice20
Guice30
Guice40
Guice41
Guice42
Guice421
Guice422
Guice423
Guice500
Guice501
Guice510
Guice600
Guice700
GuiceDiscussions
GuiceInKotlin
GuicePersist
GuicePersistMultiModules
Home
InjectOnlyDirectDependencies
InjectingProviders
InjectingTheInjector
InjectionPoints
Injections
InspectingModules
InstanceBindings
JPA
JSR330
JustInTimeBindings
KeepConstructorsHidden
LinkedBindings
MentalModel
MinimizeMutability
ModulesShouldBeFastAndSideEffectFree
Motivation
Multibindings
OSGi
OptionalAOP
OrganizeModulesByFeature
PreferAtProvides
ProviderBindings
ProvidesMethods
RestrictedBindingSource
Scopes
ServletExtensionSPI
ServletModule
ServletRegexKeyMapping
Servlets
SpringComparison
Struts2Integration
ThrowingProviders
ToConstructorBindings
Transactions
UntargettedBindings
UseNullable
Clone
9
UntargettedBindings
Copybara-Service edited this page 2024-03-26 07:20:05 -07:00
Table of Contents
Untargeted Bindings
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 untargeted binding informs the injector about a type, so it
may prepare dependencies eagerly. Untargeted 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 if 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);
Untargeted bindings are often used to register a type in a Module to ensure
that Guice is aware of the type. Registering those types is required to make
them eligible for injection when JIT is disabled.
-
User's Guide
-
Integration
-
Extensions
-
Internals
-
Releases
-
Community