Interface InstanceFactory

All Known Subinterfaces:
ConfigurableInstanceFactory
All Known Implementing Classes:
DefaultInstanceFactory

public interface InstanceFactory
Manages dependency injection of a set of bindings between Keys and Suppliers lifecycle-bound to Scopes. 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 Details

    • getFactory

      <T> Supplier<T> getFactory(ResolvableKey<T> resolvableKey)
      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 for
      aliases - alias names to include in the search
      dependencyChain - 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

      default <T> Supplier<T> getFactory(Key<T> key, Collection<String> aliases)
      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 for
      aliases - alias names to include in the search
      Returns:
      a factory for the provided key with the given dependency chain context
    • getFactory

      default <T> Supplier<T> getFactory(Key<T> key)
      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

      default <T> Supplier<T> getFactory(Class<T> clazz)
      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

      default <T> T getInstance(Key<T> key)
      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

      default <T> T getInstance(Class<T> clazz)
      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

      default <T> T getInstance(ResolvableKey<T> resolvableKey)
      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

      default <T> T getInstance(Key<T> key, Collection<String> aliases, DependencyChain dependencyChain)
      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 of
      aliases - alias names to include in the search
      dependencyChain - chain of dependencies (possibly empty) already being created in the context of this instance lookup
      Returns:
      an instance matching the provided key
    • getInstance

      default <T> T getInstance(Key<T> key, DependencyChain dependencyChain)
      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 matching
      dependencyChain - chain of dependencies (possibly empty) already being created in the context of this instance lookup
      Returns:
      an instance matching the provided key
    • getInstance

      default <T> T getInstance(Class<T> clazz, DependencyChain dependencyChain)
      Gets an instance for the provided class with dependencies.
      Type Parameters:
      T - type of instance
      Parameters:
      clazz - class to get or create an instance of
      dependencyChain - chain of dependencies (possibly empty) already being created in the context of this instance lookup
      Returns:
      an instance of the provided class
    • getTypeConverter

      default <T> TypeConverter<T> getTypeConverter(Type type)
      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

      boolean hasBinding(Key<?> key)
      Indicates if a binding exists for the provided key.