Interface InstanceFactory
- All Known Subinterfaces:
ConfigurableInstanceFactory
- All Known Implementing Classes:
DefaultInstanceFactory
public interface InstanceFactory
Manages dependency injection of a set of bindings between
Key
s and Supplier
s
lifecycle-bound to Scope
s. Keys describe the type, name, namespace, qualifier type, and order of a binding.
Suppliers are known as factories, and factories may have injectable dependencies on other bindings upon
creation. Scopes control the lifecycle of instances returned by a binding's factory. Factories for keys can be
looked up by key or by class.-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> Supplier<T>
getFactory
(Class<T> clazz) Gets a factory for instances of the provided class.default <T> Supplier<T>
getFactory
(Key<T> key) Gets a factory for instances that match the given key.default <T> Supplier<T>
getFactory
(Key<T> key, Collection<String> aliases) Gets a factory for instances that match the given key or aliases.default <T> Supplier<T>
getFactory
(Key<T> key, Collection<String> aliases, DependencyChain dependencyChain) Gets a factory for instances that match the given key with dependencies.<T> Supplier<T>
getFactory
(ResolvableKey<T> resolvableKey) Gets a factory for instances that match the given resolvable key.default <T> T
getInstance
(Class<T> clazz) Gets an instance for the provided class.default <T> T
getInstance
(Class<T> clazz, DependencyChain dependencyChain) Gets an instance for the provided class with dependencies.default <T> T
getInstance
(Key<T> key) Gets an instance that matches the provided key.default <T> T
getInstance
(Key<T> key, Collection<String> aliases, DependencyChain dependencyChain) Gets an instance that matches the given key with aliases and dependencies.default <T> T
getInstance
(Key<T> key, DependencyChain dependencyChain) Gets an instance that matches the provided key with dependencies.default <T> T
getInstance
(ResolvableKey<T> resolvableKey) Gets an instance that matches the given resolvable key.default <T> TypeConverter<T>
getTypeConverter
(Type type) Gets a type converter for the provided type.boolean
hasBinding
(Key<?> key) Indicates if a binding exists for the provided key.
-
Method Details
-
getFactory
Gets a factory for instances that match the given resolvable key.- Type Parameters:
T
- return type of factory- Parameters:
resolvableKey
- key with alias and dependency chain to look up a factory for- Returns:
- a factory for the given resolvable key
-
getFactory
default <T> Supplier<T> getFactory(Key<T> key, Collection<String> aliases, DependencyChain dependencyChain) Gets a factory for instances that match the given key with dependencies. This is used for recursive factory lookups while initializing dependent factories.- Type Parameters:
T
- return type of factory- Parameters:
key
- key to look up a factory foraliases
- alias names to include in the searchdependencyChain
- chain of dependencies (possibly empty) already being created in the context of this factory lookup- Returns:
- a factory for the provided key with the given dependency chain context
-
getFactory
Gets a factory for instances that match the given key or aliases.- Type Parameters:
T
- return type of factory- Parameters:
key
- key to look up a factory foraliases
- alias names to include in the search- Returns:
- a factory for the provided key with the given dependency chain context
-
getFactory
Gets a factory for instances that match the given key.- Type Parameters:
T
- return type of factory- Parameters:
key
- key to look up a factory for- Returns:
- a factory for the provided key
-
getFactory
Gets a factory for instances of the provided class.- Type Parameters:
T
- return type of factory- Parameters:
clazz
- class to look up a factory for- Returns:
- a factory for the provided class
-
getInstance
Gets an instance that matches the provided key.- Type Parameters:
T
- type of instance- Parameters:
key
- key to get or create an instance matching- Returns:
- an instance matching the provided key
-
getInstance
Gets an instance for the provided class.- Type Parameters:
T
- type of instance- Parameters:
clazz
- class to get or create an instance of- Returns:
- an instance of the provided class
-
getInstance
Gets an instance that matches the given resolvable key.- Type Parameters:
T
- type of instance- Parameters:
resolvableKey
- key to get or create an instance of- Returns:
- an instance matching the provided key
-
getInstance
Gets an instance that matches the given key with aliases and dependencies.- Type Parameters:
T
- type of instance- Parameters:
key
- key to get or create an instance ofaliases
- alias names to include in the searchdependencyChain
- chain of dependencies (possibly empty) already being created in the context of this instance lookup- Returns:
- an instance matching the provided key
-
getInstance
Gets an instance that matches the provided key with dependencies.- Type Parameters:
T
- type of instance- Parameters:
key
- key to get or create an instance matchingdependencyChain
- chain of dependencies (possibly empty) already being created in the context of this instance lookup- Returns:
- an instance matching the provided key
-
getInstance
Gets an instance for the provided class with dependencies.- Type Parameters:
T
- type of instance- Parameters:
clazz
- class to get or create an instance ofdependencyChain
- chain of dependencies (possibly empty) already being created in the context of this instance lookup- Returns:
- an instance of the provided class
-
getTypeConverter
Gets a type converter for the provided type.- Type Parameters:
T
- the type to convert to- Parameters:
type
- target type of type converter to get- Returns:
- a type converter for the requested type if available
-
hasBinding
Indicates if a binding exists for the provided key.
-