Package io.bootique.di.spi
Class DefaultInjector
java.lang.Object
io.bootique.di.spi.DefaultInjector
- All Implemented Interfaces:
Injector
A default implementations of a DI injector.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDefaultInjector(Set<DefaultInjector.Options> options, InjectorPredicates predicates, BQModule... modules) -
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.
-
Constructor Details
-
DefaultInjector
public DefaultInjector(Set<DefaultInjector.Options> options, InjectorPredicates predicates, BQModule... modules)
-
-
Method Details
-
getInstance
Description copied from interface:InjectorReturns 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.- Specified by:
getInstancein interfaceInjector
-
getInstance
Description copied from interface:InjectorReturns 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.- Specified by:
getInstancein interfaceInjector
-
getProvider
- Specified by:
getProviderin interfaceInjector
-
getProvider
- Specified by:
getProviderin interfaceInjector
-
hasProvider
- Specified by:
hasProviderin interfaceInjector- Parameters:
type- binding type to check- Returns:
- is provider for given type registered
-
hasProvider
- Specified by:
hasProviderin interfaceInjector- Parameters:
key- binding key to check- Returns:
- is provider for given key registered
-
injectMembers
Description copied from interface:InjectorPerforms 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.- Specified by:
injectMembersin interfaceInjector
-
shutdown
public void shutdown()Description copied from interface:InjectorA 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
Description copied from interface:InjectorReturns collection ofKeybound to given type, regardless of additional qualifiers (annotations and/or names).- Specified by:
getKeysByTypein interfaceInjector- Type Parameters:
T- type- Parameters:
type- interested class object- Returns:
- collection of keys bound to given type
-