Class DefaultDependencyInjector
java.lang.Object
com.github.kaktushose.jda.commands.dependency.DefaultDependencyInjector
- All Implemented Interfaces:
DependencyInjector
Default implementation of
DependencyInjector
.- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Scans the whole classpath for methods annotated withProduces
.void
Injects all registered dependencies with the corresponding value.void
registerDependencies
(@NotNull Class<?> clazz, @NotNull List<Field> fields) Registers fields inside a class as dependencies.void
registerProvider
(@NotNull Object provider) Takes an instance of a class and scans it for methods annotated withProduces
.
-
Constructor Details
-
DefaultDependencyInjector
public DefaultDependencyInjector()Create a new DependencyInjector.
-
-
Method Details
-
index
Description copied from interface:DependencyInjector
Scans the whole classpath for methods annotated withProduces
. If found, creates a new instance of the declaring class and will call the method to retrieve the object and register it as a dependency. If the method is declared as static, no instance will be created. UseDependencyInjector.registerProvider(Object)
if no new instance of the declaring class should be created.- Specified by:
index
in interfaceDependencyInjector
- Parameters:
clazz
- a class of the classpath to scanpackages
- package(s) to exclusively scan
-
registerProvider
Description copied from interface:DependencyInjector
Takes an instance of a class and scans it for methods annotated withProduces
. If found, will call the method to retrieve the object and register it as a dependency.- Specified by:
registerProvider
in interfaceDependencyInjector
- Parameters:
provider
- instance of the class to scan
-
registerDependencies
public void registerDependencies(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull List<Field> fields) Description copied from interface:DependencyInjector
Registers fields inside a class as dependencies.- Specified by:
registerDependencies
in interfaceDependencyInjector
- Parameters:
clazz
- the declaring classfields
- the dependencies to register
-
inject
Description copied from interface:DependencyInjector
Injects all registered dependencies with the corresponding value. If no value is presentnull
gets injected.- Specified by:
inject
in interfaceDependencyInjector
-