Package me.datafox.dfxengine.injector
Class InjectorImpl
java.lang.Object
me.datafox.dfxengine.injector.InjectorImpl
- All Implemented Interfaces:
Injector
A dependency injector. For general information, see
README.md on GitHub. Use
InjectorBuilder to build.
getComponent(Class), getComponent(TypeRef), getComponent(Class, Class),
getComponent(TypeRef, TypeRef), getComponents(Class), getComponents(TypeRef),
getComponents(Class, Class) and getComponents(TypeRef, TypeRef) can be used to retrieve components.
The requesting parameter is only relevant when requesting components that have
InstantiationPolicy.PER_INSTANCE.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescription<T> TgetComponent(Class<T> type) Returns a singleComponentof the specified type.<T,R> T getComponent(Class<T> type, Class<R> requesting) Returns a singleComponentof the specified type.<T> TgetComponent(TypeRef<T> type) Returns a singleComponentof the specified type.<T,R> T getComponent(TypeRef<T> type, TypeRef<R> requesting) Returns a singleComponentof the specified type.<T> List<T> getComponents(Class<T> type) ReturnsComponentsof the specified type.<T,R> List <T> getComponents(Class<T> type, Class<R> requesting) ReturnsComponentsof the specified type.<T> List<T> getComponents(TypeRef<T> type) ReturnsComponentsof the specified type.<T,R> List <T> getComponents(TypeRef<T> type, TypeRef<R> requesting) ReturnsComponentsof the specified type.<T> voidinvokeEvent(T event) Calls allEventHandlerswith the specified event that can accept its type as a parameter.voidinvokeEvents(Collection<?> events) Calls allEventHandlerswith the specified events that can accept their types as parameters.
-
Method Details
-
getComponent
Returns a singleComponentof the specified type. If theClasshas type parameters, useInjector.getComponent(TypeRef)instead. Otherwise, an exception is thrown. An exception is also thrown if multiple Components or no Components are present.- Specified by:
getComponentin interfaceInjector- Type Parameters:
T- type of theComponentto be requested- Parameters:
type- type of theComponentto be requested- Returns:
Componentof the specified type- Throws:
ParameterCountMismatchException- if theClasshas type parametersMultipleDependenciesPresentException- if multipleComponentswith the specified type are presentNoDependenciesPresentException- if noComponentswith the specified type are present
-
getComponent
Returns a singleComponentof the specified type. If multiple Components or no Components are present, an exception is thrown.- Specified by:
getComponentin interfaceInjector- Type Parameters:
T- type of theComponentto be requested- Parameters:
type- type of theComponentto be requested- Returns:
Componentof the specified type- Throws:
MultipleDependenciesPresentException- if multipleComponentswith the specified type are presentNoDependenciesPresentException- if noComponentswith the specified type are present
-
getComponent
Returns a singleComponentof the specified type. If the Component hasInstantiationPolicy.PER_INSTANCEand depends onInstantiationDetails, therequestingparameter will be used forInstantiationDetails. If theClasshas type parameters, useInjector.getComponent(TypeRef)instead. An exception is also thrown if multiple Components or no Components are present.- Specified by:
getComponentin interfaceInjector- Type Parameters:
T- type of theComponentto be requestedR- type of the object requesting theComponent- Parameters:
type- type of theComponentto be requestedrequesting- type of the object requesting theComponent- Returns:
Componentof the specified type- Throws:
ParameterCountMismatchException- if the type or requestingClasshas type parametersMultipleDependenciesPresentException- if multipleComponentswith the specified type are presentNoDependenciesPresentException- if noComponentswith the specified type are present
-
getComponent
Returns a singleComponentof the specified type. If the Component hasInstantiationPolicy.PER_INSTANCEand depends onInstantiationDetails, therequestingparameter will be used forInstantiationDetails. If multiple Components or no Components are present, an exception is thrown.- Specified by:
getComponentin interfaceInjector- Type Parameters:
T- type of theComponentto be requestedR- type of the object requesting theComponent- Parameters:
type- type of theComponentto be requestedrequesting- type of the object requesting theComponent- Returns:
Componentof the specified type- Throws:
MultipleDependenciesPresentException- if multipleComponentswith the specified type are presentNoDependenciesPresentException- if noComponentswith the specified type are present
-
getComponents
ReturnsComponentsof the specified type. If theClasshas type parameters, useInjector.getComponents(TypeRef)instead. Otherwise, an exception is thrown.- Specified by:
getComponentsin interfaceInjector- Type Parameters:
T- type of theComponentsto be requested- Parameters:
type- type of theComponentsto be requested- Returns:
ListofComponentsof the specified type- Throws:
ParameterCountMismatchException- if theClasshas type parameters
-
getComponents
ReturnsComponentsof the specified type.- Specified by:
getComponentsin interfaceInjector- Type Parameters:
T- type of theComponentsto be requested- Parameters:
type- type of theComponentsto be requested- Returns:
ListListofComponentsof the specified type
-
getComponents
ReturnsComponentsof the specified type. If any of the Components haveInstantiationPolicy.PER_INSTANCEand depend onInstantiationDetails, therequestingparameter will be used forInstantiationDetails. If theClasshas type parameters, useInjector.getComponent(TypeRef)instead. Otherwise, an exception is thrown.- Specified by:
getComponentsin interfaceInjector- Type Parameters:
T- type of theComponentsto be requestedR- type of the object requesting theComponents- Parameters:
type- type of theComponentsto be requestedrequesting- type of the object requesting theComponents- Returns:
ListofComponentsof the specified type- Throws:
ParameterCountMismatchException- if the type or requestingClasshas type parameters
-
getComponents
ReturnsComponentsof the specified type. If any of the Components havInstantiationPolicy.PER_INSTANCEand depend onInstantiationDetails, therequestingparameter will be used forInstantiationDetails.- Specified by:
getComponentsin interfaceInjector- Type Parameters:
T- type of theComponentsto be requestedR- type of the object requesting theComponents- Parameters:
type- type of theComponentsto be requestedrequesting- type of the object requesting theComponents- Returns:
ListofComponentsof the specified type
-
invokeEvent
public <T> void invokeEvent(T event) Calls allEventHandlerswith the specified event that can accept its type as a parameter. If the event has type parameters, it must implementParametricEvent.- Specified by:
invokeEventin interfaceInjector- Type Parameters:
T- type of the event- Parameters:
event- event to be invoked
-
invokeEvents
Calls allEventHandlerswith the specified events that can accept their types as parameters. If an event has type parameters, it must implementParametricEvent.- Specified by:
invokeEventsin interfaceInjector- Parameters:
events- events to be invoked
-