Record Class DefaultInjectionLayer<I extends Injector>

java.lang.Object
java.lang.Record
eu.cloudnetservice.driver.inject.DefaultInjectionLayer<I>
Type Parameters:
I - the type of injector this layer uses.
Record Components:
injector - the injector to use for the layer.
autoModule - the auto registry to use for the layer.
name - the name of this injection layer.
All Implemented Interfaces:
Named, InjectionLayer<I>, AutoCloseable

@Internal record DefaultInjectionLayer<I extends Injector>(I extends Injector injector, @NonNull dev.derklaro.aerogel.auto.AerogelAutoModule autoModule, @NonNull String name) extends Record implements InjectionLayer<I>
The default implementation for of an injector layer.
Since:
4.0
  • Field Details

  • Constructor Details

    • DefaultInjectionLayer

      DefaultInjectionLayer(@NonNull I injector, @NonNull @NonNull dev.derklaro.aerogel.auto.AerogelAutoModule autoModule, @NonNull @NonNull String name)
      Creates an instance of a DefaultInjectionLayer record class.
      Parameters:
      injector - the value for the injector record component
      autoModule - the value for the autoModule record component
      name - the value for the name record component
  • Method Details

    • injector

      @NonNull public I injector()
      Gets the underlying injector of this layer.
      Specified by:
      injector in interface InjectionLayer<I extends Injector>
      Returns:
      the underlying injector of this layer.
    • instance

      public <T> @UnknownNullability T instance(@NonNull @NonNull Class<T> type)
      Convince method to create or get the instance of the given class type.
      Specified by:
      instance in interface InjectionLayer<I extends Injector>
      Type Parameters:
      T - the type of the class modeled by the given class object.
      Parameters:
      type - the type of the element to get.
      Returns:
      the constructed instance of the class type, may be null.
    • instance

      public <T> @UnknownNullability T instance(@NonNull @NonNull BindingKey<T> bindingKey)
      Convince method to create or get the instance of the given binding key.
      Specified by:
      instance in interface InjectionLayer<I extends Injector>
      Type Parameters:
      T - the type of the return value modeled by the given binding key.
      Parameters:
      bindingKey - the binding key for the instance to resolve.
      Returns:
      the constructed instance of the class type, may be null.
    • instance

      public <T> @UnknownNullability T instance(@NonNull @NonNull Class<T> type, @NonNull @NonNull UnaryOperator<InjectionRequest<T>> decorator)
      Convince method to create or get the instance of the given type, while allowing to specifically influence the injection context.
      Specified by:
      instance in interface InjectionLayer<I extends Injector>
      Type Parameters:
      T - the type of the return value modeled by the given element.
      Parameters:
      type - the type of the element to get.
      decorator - the decorator for the injection request.
      Returns:
      the constructed instance of the class type, may be null.
    • install

      public void install(@NonNull @NonNull UninstalledBinding<?> binding)
      Installs the uninstalled binding into the underlying injector.
      Specified by:
      install in interface InjectionLayer<I extends Injector>
      Parameters:
      binding - the binding to install.
    • install

      public void install(@NonNull @NonNull DynamicBinding binding)
      Installs a dynamic binding into the underlying injector. The dynamic binding can be used to provide bindings based on the presence of annotations and other matching criteria. Dynamic bindings have a lower priority than UninstalledBinding.
      Specified by:
      install in interface InjectionLayer<I extends Injector>
      Parameters:
      binding - the dynamic binding to install.
    • installAutoConfigureBindings

      public void installAutoConfigureBindings(@NonNull @NonNull ClassLoader loader, @NonNull @NonNull String component)
      Installs the autoconfiguration bindings for the given component. For this method to work the autoconfiguration bindings must be located at autoconfigure/<component>.aero.

      This method binds the autoconfiguration bindings to the underlying injector of this layer.

      Specified by:
      installAutoConfigureBindings in interface InjectionLayer<I extends Injector>
      Parameters:
      loader - the loader in which the file resource is located.
      component - the name of the component to load the autoconfiguration bindings of.
    • asUncloseable

      @NonNull public @NonNull InjectionLayer<I> asUncloseable()
      Makes this injection layer not closeable, returning the same layer if it is already not closeable.
      Specified by:
      asUncloseable in interface InjectionLayer<I extends Injector>
      Returns:
      the same injection layer from the functionality, but not closeable.
    • register

      @NonNull public @NonNull InjectionLayer<I> register(@NonNull @NonNull Object... hints)
      Registers this injection layer to the injection layer registry. Subsequent calls to InjectionLayer.findLayerOf(Object) will be able to resolve the layer if the given object value is the exact the same as given as one of the hints (exact as by using the == compare operation).

      Note that the layer lookup order is predictable based on the call order of register. If different layers are registered for the same objects, the first layer to be registered will be found.

      Specified by:
      register in interface InjectionLayer<I extends Injector>
      Parameters:
      hints - the hints to use for the layer registration.
      Returns:
      the same layer as used to call the method, for chaining.
    • close

      public void close()
      Closes this injector and removes all leftover bindings (if any).
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface InjectionLayer<I extends Injector>
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • autoModule

      @NonNull public @NonNull dev.derklaro.aerogel.auto.AerogelAutoModule autoModule()
      Returns the value of the autoModule record component.
      Returns:
      the value of the autoModule record component
    • name

      @NonNull public @NonNull String name()
      Returns the value of the name record component.
      Specified by:
      name in interface InjectionLayer<I extends Injector>
      Specified by:
      name in interface Named
      Returns:
      the value of the name record component