Class Injector.Builder
java.lang.Object
be.imgn.inject.Injector.Builder
- Enclosing interface:
Injector
Builds an
Injector that overlays explicit instance bindings on top of the discovered graph. An override
replaces any discovered binding for the same key, including where that key is an injected dependency of another
bean, which makes it a convenient seam for substituting fakes in tests.-
Method Summary
Modifier and TypeMethodDescription<T> Injector.BuilderReturns this builder, bindinginstancetokey.<T> Injector.BuilderReturns this builder, bindinginstanceas the unqualified key fortype.<T> Injector.BuilderbindProvider(Key<T> key, Provider<T> provider) Returns this builder, binding a provider evaluated on every resolution forkey.<T> Injector.BuilderbindProvider(Class<T> type, Provider<T> provider) Returns this builder, binding a provider evaluated on every resolution fortype.build()Returns a new injector applying the configured overrides.
-
Method Details
-
bind
Returns this builder, bindinginstanceas the unqualified key fortype.- Type Parameters:
T- the bound type- Parameters:
type- the bound typeinstance- the instance to return for that type- Returns:
- this builder, binding
instanceas the unqualified key fortype
-
bind
Returns this builder, bindinginstancetokey.- Type Parameters:
T- the bound type- Parameters:
key- the binding keyinstance- the instance to return for that key- Returns:
- this builder, binding
instancetokey
-
bindProvider
Returns this builder, binding a provider evaluated on every resolution fortype.- Type Parameters:
T- the bound type- Parameters:
type- the bound typeprovider- the provider to consult for that type- Returns:
- this builder, binding a provider evaluated on every resolution for
type
-
bindProvider
Returns this builder, binding a provider evaluated on every resolution forkey.- Type Parameters:
T- the bound type- Parameters:
key- the binding keyprovider- the provider to consult for that key- Returns:
- this builder, binding a provider evaluated on every resolution for
key
-
build
Returns a new injector applying the configured overrides.- Returns:
- a new injector applying the configured overrides
- Throws:
UnsatisfiedDependencyException- if a bean depends on a key that neither a discovered factory nor an override binds; the message lists every such dependency. The dependencies of a bean of a child-local scope are checked when a child hosting that scope is built instead.RuntimeException- any exception thrown building a construction listener or anEagersingleton, once the singletons already built are destroyed
-