Package io.bootique.di
Interface Injector
- All Known Implementing Classes:
DefaultInjector
public interface Injector
A facade to the Bootique DI container. To create an injector use
DIBootstrap static methods.-
Method Summary
Modifier and TypeMethodDescription<T> TgetInstance(Key<T> key) Returns a service instance bound in the container for a specific binding key.<T> TgetInstance(Class<T> type) Returns a service instance bound in the container for a specific type.<T> Collection<Key<T>>getKeysByType(Class<T> type) Returns collection ofKeybound to given type, regardless of additional qualifiers (annotations and/or names).<T> javax.inject.Provider<T>getProvider(Key<T> key) <T> javax.inject.Provider<T>getProvider(Class<T> type) booleanhasProvider(Key<?> key) booleanhasProvider(Class<?> type) voidinjectMembers(Object object) Performs field injection on a given object, ignoring constructor injection.voidshutdown()A lifecycle method that let's the injector's services to clean up their state and release resources.
-
Method Details
-
getInstance
Returns a service instance bound in the container for a specific type. If the type is not explicitly bound to an implementation, a provider, or a provider method, tries to create an object of this type on the fly. In that case, if an object can not be created by the Injector (e.g. if it is an interface), throwsDIRuntimeException.- Throws:
DIRuntimeException
-
getInstance
Returns a service instance bound in the container for a specific binding key. ThrowsDIRuntimeExceptionif the key is not bound, or an instance can not be created.- Throws:
DIRuntimeException
-
getProvider
- Throws:
DIRuntimeException
-
getProvider
- Throws:
DIRuntimeException
-
hasProvider
- Parameters:
type- binding type to check- Returns:
- is provider for given type registered
- Throws:
DIRuntimeException
-
hasProvider
- Parameters:
key- binding key to check- Returns:
- is provider for given key registered
- Throws:
DIRuntimeException
-
injectMembers
Performs field injection on a given object, ignoring constructor injection. This method is rarely used directly, as objects that require dependency injection are usually themselves obtained from the injector, and have all their fields already initialized.Using this method inside a custom
Providerwill most likely result in double injection, as each custom provider is wrapped in a field-injecting provider by the DI container. Instead, custom providers must initialize object properties manually, obtaining dependencies from Injector. -
shutdown
void shutdown()A lifecycle method that let's the injector's services to clean up their state and release resources. This method would normally generate a scope end event for the injector's one and only singleton scope. -
getKeysByType
Returns collection ofKeybound to given type, regardless of additional qualifiers (annotations and/or names).- Type Parameters:
T- type- Parameters:
type- interested class object- Returns:
- collection of keys bound to given type
-