mirror of
https://github.com/google/guice.git
synced 2024-04-21 12:32:36 +00:00
Page:
BindingResolution
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
5
BindingResolution
Copybara-Service edited this page 2021-01-22 13:44:10 -08:00
Table of Contents
Binding Resolution
How the Injector resolves injection requests
The injector's process of resolving an injection request depends on the bindings and the annotations of the types involved. Here's how an injection request is resolved:
- Use explicit bindings.
- If the binding links to another, follow this resolution algorithm for that.
- If the binding specifies an instance, return that.
- If the binding specifies a provider, use that.
- Ask a parent injector. If this injector has a parent injector, ask that to resolve the binding. If it succeeds, use that. Otherwise proceed.
- Ask child injectors. If any child injector already has this binding, give up. A banned list of bindings from child injectors is kept so injectors don't need to maintain references to their child injectors.
- Handle Provider injections. If the type is
Provider<T>, resolveTinstead, using the same binding annotation, if it exists. - Convert constants. If there is a constant string bound with the same
annotation, and a
TypeConverterthat supports this type, use the converted String. - If the dependency has a binding annotation, give up. Guice will not create default bindings for annotated dependencies.
- If the dependency is an array or enum, give up.
- Handle TypeLiteral injections. If the type is
TypeLiteral<T>, inject that value, using context for the value of the type parameter. - Use resolution annotations. If the dependency's type has
@ImplementedByor@ProvidedBy, lookup the binding for the referenced type and use that. - If the dependency is abstract or a non-static inner class, give up.
- Use a single
@Injector public no-arguments constructor.- Validate bindings for all dependencies — the constructor's parameters,
plus
@Injectmethods and fields of the type and all supertypes. - Invoke the constructor.
- Inject all fields. Supertype fields are injected before subtype fields.
- Inject all methods. Supertype methods are injected before subtype methods.
- Validate bindings for all dependencies — the constructor's parameters,
plus
-
User's Guide
-
Integration
-
Extensions
-
Internals
-
Releases
-
Community