Class InjectorImpl

java.lang.Object
org.apache.maven.di.impl.InjectorImpl
All Implemented Interfaces:
Injector

public class InjectorImpl extends Object implements Injector
  • Constructor Details

    • InjectorImpl

      public InjectorImpl()
  • Method Details

    • getInstance

      @Nonnull public <T> T getInstance(@Nonnull Class<T> key)
      Description copied from interface: Injector
      Retrieves or creates an instance of the specified type.
      Specified by:
      getInstance in interface Injector
      Type Parameters:
      T - the type to retrieve
      Parameters:
      key - the class representing the type to retrieve
      Returns:
      an instance of the requested type
    • getInstance

      @Nonnull public <T> T getInstance(@Nonnull Key<T> key)
      Description copied from interface: Injector
      Retrieves or creates an instance for the specified key.

      This method allows retrieval of instances with specific qualifiers or generic type parameters.

      Specified by:
      getInstance in interface Injector
      Type Parameters:
      T - the type to retrieve
      Parameters:
      key - the key identifying the instance to retrieve
      Returns:
      an instance matching the requested key
    • injectInstance

      public <T> void injectInstance(@Nonnull T instance)
      Description copied from interface: Injector
      Performs field and method injection on an existing instance.

      This method will inject dependencies into annotated fields and methods of the provided instance but will not create a new instance.

      Specified by:
      injectInstance in interface Injector
      Type Parameters:
      T - the type of the instance
      Parameters:
      instance - the instance to inject dependencies into
    • discover

      @Nonnull public Injector discover(@Nonnull ClassLoader classLoader)
      Description copied from interface: Injector
      Configures the injector to discover injectable components from the specified ClassLoader.

      This method scans for classes annotated with injection-related annotations and automatically registers them with the injector.

      Specified by:
      discover in interface Injector
      Parameters:
      classLoader - the ClassLoader to scan for injectable components
      Returns:
      this injector instance for method chaining
    • bindScope

      @Nonnull public Injector bindScope(@Nonnull Class<? extends Annotation> scopeAnnotation, @Nonnull Scope scope)
      Description copied from interface: Injector
      Binds a scope annotation to its implementation.

      This allows custom scopes to be registered with the injector. The scope annotation must be annotated with Scope.

      Specified by:
      bindScope in interface Injector
      Parameters:
      scopeAnnotation - the annotation class that defines the scope
      scope - the scope implementation
      Returns:
      this injector instance for method chaining
    • bindScope

      @Nonnull public Injector bindScope(@Nonnull Class<? extends Annotation> scopeAnnotation, @Nonnull Supplier<Scope> scope)
      Description copied from interface: Injector
      Binds a scope annotation to a supplier that creates scope implementations.

      Similar to Injector.bindScope(Class, Scope) but allows lazy creation of scope implementations.

      Specified by:
      bindScope in interface Injector
      Parameters:
      scopeAnnotation - the annotation class that defines the scope
      scope - supplier that creates scope implementations
      Returns:
      this injector instance for method chaining
    • bindInstance

      @Nonnull public <U> Injector bindInstance(@Nonnull Class<U> clazz, @Nonnull U instance)
      Description copied from interface: Injector
      Binds a specific instance to a class type.

      This method allows pre-created instances to be used for injection instead of having the injector create new instances.

      Specified by:
      bindInstance in interface Injector
      Type Parameters:
      U - the type of the instance
      Parameters:
      clazz - the class to bind to
      instance - the instance to use for injection
      Returns:
      this injector instance for method chaining
    • bindImplicit

      @Nonnull public Injector bindImplicit(@Nonnull Class<?> clazz)
      Description copied from interface: Injector
      Registers a class for implicit binding.

      Implicit bindings allow the injector to create instances of classes without explicit binding definitions. The class must have appropriate injection annotations.

      Specified by:
      bindImplicit in interface Injector
      Parameters:
      clazz - the class to register for implicit binding
      Returns:
      this injector instance for method chaining
    • bind

      protected <U> Injector bind(Key<U> key, Binding<U> b)
    • getBindings

      protected <T> Set<Binding<T>> getBindings(Key<T> key)
    • getBoundKeys

      protected Set<Key<?>> getBoundKeys()
    • getBindings

      public Map<Key<?>,Set<Binding<?>>> getBindings()
    • getCompiledBinding

      public <Q> Supplier<Q> getCompiledBinding(Dependency<Q> dep)
    • compile

      protected <Q> Supplier<Q> compile(Binding<Q> binding)
    • doBindImplicit

      protected void doBindImplicit(Key<?> key, Binding<?> binding)
    • map

      protected <K, V, T> Map<K,V> map(Map<K,T> map, Function<T,V> mapper)
    • list

      protected <Q, T> List<Q> list(List<T> bindingList, Function<T,Q> mapper)