Interface IDependencyInjector<BindableType extends IBindable>
- All Known Subinterfaces:
IDhApiEventInjector
- All Known Implementing Classes:
ApiEventInjector
,DependencyInjector
public interface IDependencyInjector<BindableType extends IBindable>
-
Method Summary
Modifier and TypeMethodDescriptionvoid
bind
(Class<? extends BindableType> dependencyInterface, BindableType dependencyImplementation) Links the given implementation object to an interface, so it can be referenced later.boolean
checkIfClassExtends
(Class<?> classToTest, Class<?> extensionToLookFor) Checks if classToTest extends the given class.boolean
checkIfClassImplements
(Class<?> classToTest, Class<?> interfaceToLookFor) Checks if classToTest (or one of its ancestors) implements the given interface.void
clear()
Removes all bound dependencies.<T extends BindableType>
TDoes not return incomplete dependencies.<T extends BindableType>
TReturns a dependency of type T if one has been bound.<T extends BindableType>
ArrayList<T> Returns all dependencies of type T that have been bound.void
Runs delayed setup for any dependencies that require it.
-
Method Details
-
bind
void bind(Class<? extends BindableType> dependencyInterface, BindableType dependencyImplementation) throws IllegalStateException, IllegalArgumentException Links the given implementation object to an interface, so it can be referenced later.- Parameters:
dependencyInterface
- The interface (or parent class) the implementation object should implement.dependencyImplementation
- An object that implements the dependencyInterface interface.- Throws:
IllegalStateException
- if the interface has already been bound and duplicates aren't allowedIllegalArgumentException
- if the implementation object doesn't implement the interface
-
checkIfClassImplements
Checks if classToTest (or one of its ancestors) implements the given interface. -
checkIfClassExtends
Checks if classToTest extends the given class. -
get
Does not return incomplete dependencies.
Seeget(Class, boolean)
for full documentation.- Throws:
ClassCastException
- See Also:
-
getAll
Returns all dependencies of type T that have been bound.
Returns an empty list if no dependencies have been bound.- Type Parameters:
T
- class of the dependency (inferred from the objectClass parameter)- Parameters:
interfaceClass
- Interface of the dependency- Returns:
- the dependency of type T
- Throws:
ClassCastException
- If the dependency isn't able to be cast to type T. (this shouldn't normally happen, unless the bound object changed somehow)
-
get
<T extends BindableType> T get(Class<T> interfaceClass, boolean allowIncompleteDependencies) throws ClassCastException Returns a dependency of type T if one has been bound.
Returns null if a dependency hasn't been bound.
If the handler allows duplicate bindings, this will return the first bound dependency.- Type Parameters:
T
- class of the dependency (inferred from the interfaceClass parameter)- Parameters:
interfaceClass
- Interface of the dependencyallowIncompleteDependencies
- If true this method will also return dependencies that haven't completed their delayed setup.- Returns:
- the dependency of type T
- Throws:
ClassCastException
- If the dependency isn't able to be cast to type T. (this shouldn't normally happen, unless the bound object changed somehow)
-
clear
void clear()Removes all bound dependencies. -
runDelayedSetup
void runDelayedSetup()Runs delayed setup for any dependencies that require it.
-