Class InjectionLayerProvider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static InjectionLayer<dev.derklaro.aerogel.Injector> private static InjectionLayer<dev.derklaro.aerogel.Injector> private static final Typeprivate static final Typeprivate static final Class<InjectionLayer> (package private) static final InjectionLayerRegistry -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> boot()Get the singleton boot injection layer.static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> child(@NonNull InjectionLayer<dev.derklaro.aerogel.Injector> parent, @NonNull String name) Constructs a new child layer for the given parent layer.private static <I extends dev.derklaro.aerogel.Injector>
@NonNull InjectionLayer<I> configuredLayer(@NonNull String name, I injector, @NonNull Consumer<InjectionLayer<I>> configurator) Provides a fresh injection layer, with no bindings configured to the returned injector.static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> configuredLayer(@NonNull String name, @NonNull Consumer<InjectionLayer<dev.derklaro.aerogel.Injector>> configurator) Provides a fresh injection layer, with no bindings configured to the returned injector.static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> ext()Returns the singleton injection layer which should be used for all kinds of external component injection (like plugins).static @NonNull InjectionLayer<?> findLayerOf(@NonNull Object object, @NonNull InjectionLayer<?> def) Finds the injection layer associated with the given object or returns the given default injection layer.static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> Provides a fresh injection layer, with no bindings configured to the returned injector, except for a binding to the layer itself with the provided name.private static voidregisterBindings(@NonNull dev.derklaro.aerogel.Injector injector, @NonNull jakarta.inject.Provider<InjectionLayer<?>> layer, @NonNull String name, @NonNull Consumer<dev.derklaro.aerogel.binding.UninstalledBinding<?>> register) static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> specifiedChild(@NonNull InjectionLayer<? extends dev.derklaro.aerogel.Injector> parent, @NonNull String name, @NonNull Consumer<dev.derklaro.aerogel.TargetedInjectorBuilder> configurator) Constructs a new child layer for the given parent layer.private static voidvalidateName(@NonNull String name) Validates the given layer name, throwing an exception if the name is invalid.
-
Field Details
-
REGISTRY
-
RAW_ELEMENT
-
GENERIC_ELEMENT
-
INJECTOR_ELEMENT
-
boot
-
ext
-
-
Constructor Details
-
InjectionLayerProvider
private InjectionLayerProvider()
-
-
Method Details
-
boot
Get the singleton boot injection layer.- Returns:
- the boot injection layer.
-
ext
Returns the singleton injection layer which should be used for all kinds of external component injection (like plugins). The ext layer has all bindings of the boot layer present.- Returns:
- the singleton ext injection layer.
-
specifiedChild
@NonNull public static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> specifiedChild(@NonNull @NonNull InjectionLayer<? extends dev.derklaro.aerogel.Injector> parent, @NonNull @NonNull String name, @NonNull @NonNull Consumer<dev.derklaro.aerogel.TargetedInjectorBuilder> configurator) Constructs a new child layer for the given parent layer. All bindings from the parent layer are still visible to the child layer, but not vise-versa. The returned child layer uses a specified injector and passes it to the given configurator in order to precisely configure bindings.The new layer has a binding for the layer type with the given name in order to request injection of the given layer. Note that injecting the injector of a layer still results in the child layer injector, even if no name is present.
This type of layer should be used in a context when the constructed bindings of classes should be visible to the parent layer, while some bindings need to be specifically overridden. This can for example be a modular context, where the module description should only be visible to the current module, not to all modules.
- Parameters:
parent- the parent layer to construct the child from.name- the name of the child layer.configurator- the configurator for the layer, for convince it also provides the specified injector.- Returns:
- a new specified layer with the given parent layer.
- Throws:
NullPointerException- if the given parent layer, name or configurator is null.IllegalArgumentException- if the given name is invalid.
-
child
@NonNull public static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> child(@NonNull @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> parent, @NonNull @NonNull String name) Constructs a new child layer for the given parent layer. All bindings from the parent layer are still visible to the child layer, but not vise-versa.The new layer has a binding for the layer type with the given name in order to request injection of the given layer. Note that injecting the injector of a layer still results in the child layer injector, even if no name is present.
- Parameters:
parent- the parent layer to construct the child from.name- the name of the child layer.- Returns:
- a new layer with the given parent layer.
- Throws:
NullPointerException- if the given parent layer or name is null.IllegalArgumentException- if the given name is invalid.
-
fresh
@NonNull public static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> fresh(@NonNull @NonNull String name) Provides a fresh injection layer, with no bindings configured to the returned injector, except for a binding to the layer itself with the provided name.- Parameters:
name- the name of the new injection layer.- Returns:
- a new injection layer with no configured bindings.
- Throws:
NullPointerException- if the given name is null.IllegalArgumentException- if the given name is invalid.
-
configuredLayer
@NonNull public static @NonNull InjectionLayer<dev.derklaro.aerogel.Injector> configuredLayer(@NonNull @NonNull String name, @NonNull @NonNull Consumer<InjectionLayer<dev.derklaro.aerogel.Injector>> configurator) Provides a fresh injection layer, with no bindings configured to the returned injector. After construction the layer is passed to the given consumer to configure it.- Parameters:
name- the name of the injection layer.configurator- the configurator for the injection layer.- Returns:
- a new, configured injection layer with no configured bindings.
- Throws:
NullPointerException- if the given name or configurator is null.IllegalArgumentException- if the given name is invalid.
-
configuredLayer
@NonNull private static <I extends dev.derklaro.aerogel.Injector> @NonNull InjectionLayer<I> configuredLayer(@NonNull @NonNull String name, @NonNull I injector, @NonNull @NonNull Consumer<InjectionLayer<I>> configurator) Provides a fresh injection layer, with no bindings configured to the returned injector. After construction the layer is passed to the given consumer to configure it.- Type Parameters:
I- the type of injector to use for the layer.- Parameters:
name- the name of the injection layer.injector- the injector to use for the layer.configurator- the configurator for the injection layer.- Returns:
- a new, configured injection layer with no configured bindings.
- Throws:
NullPointerException- if the given name, injector or configurator is null.IllegalArgumentException- if the given name is invalid.
-
findLayerOf
@NonNull public static @NonNull InjectionLayer<?> findLayerOf(@NonNull @NonNull Object object, @NonNull @NonNull InjectionLayer<?> def) Finds the injection layer associated with the given object or returns the given default injection layer. The following search rules apply (in order):- If the given object is an
InjectionLayerHolder, the layer stored in the holder is returned. - If the given object has a layer associated in the layer registry, that layer is returned.
- If the given object is a class the associated class loader of the given class is checked.
- If the given object is not a class loader the loader of the object class is checked.
- If none of the above rules matches the given default layer is returned.
- Parameters:
object- the object to get the associated injection layer of.def- the default layer to return if no layer can be found.- Returns:
- the injection layer associated with the given object or the given default layer.
- Throws:
NullPointerException- if the given object or default layer is null.
- If the given object is an
-
validateName
Validates the given layer name, throwing an exception if the name is invalid.- Parameters:
name- the name to validate.- Throws:
NullPointerException- if the given name is null.IllegalArgumentException- if the given name is invalid.
-
registerBindings
-