| Modifier and Type | Field and Description |
|---|---|
protected InjectorConfig |
config |
protected Map<Class<?>,Object> |
objects |
| Modifier | Constructor and Description |
|---|---|
protected |
InjectorImpl(InjectorConfig config)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
<T> T |
createIfHasDependencies(Class<T> clazz)
Creates an instance of the given class if all of its dependencies are available.
|
protected Resolution<?> |
findResolutionOrFail(ResolutionContext context)
Calls the defined handlers and returns the first
Resolution that is returned based on
the provided resolution context. |
InjectorConfig |
getConfig() |
<T> T |
getIfAvailable(Class<T> clazz)
Returns the singleton of the given class if available.
|
<T> T |
getSingleton(Class<T> clazz)
Retrieves or instantiates an object of the given type (singleton scope).
|
<T> T |
newInstance(Class<T> clazz)
Request-scoped method to instantiate a new object of the given class.
|
void |
provide(Class<? extends Annotation> clazz,
Object object)
Processes an annotation with an associated object.
|
<T> void |
register(Class<? super T> clazz,
T object)
Registers an object as the singleton of the given class.
|
<T,P extends javax.inject.Provider<? extends T>> |
registerProvider(Class<T> clazz,
Class<P> providerClass)
Registers the provider class to instantiate a given class.
|
<T> void |
registerProvider(Class<T> clazz,
javax.inject.Provider<? extends T> provider)
Registers a provider for the given class.
|
protected Object |
resolveContext(ResolutionContext context)
Returns the object as defined by the given context.
|
protected Object[] |
resolveDependencies(ResolutionContext context,
Resolution<?> resolution)
Resolves the dependencies as defined by the given resolution.
|
<T> Collection<T> |
retrieveAllOfType(Class<T> clazz)
Returns all known singletons of the given type.
|
protected <T> T |
runPostConstructHandlers(T instance,
ResolutionContext context,
Resolution<?> resolution)
Invokes the handler's post construct method when appropriate.
|
protected void |
throwForUnexpectedNullDependency(ResolutionContext context)
Called when a resolved dependency is null, this method may throw an exception in the cases when this
should not happen.
|
protected InjectorConfig config
protected InjectorImpl(InjectorConfig config)
config - injector configurationInjectorBuilderpublic <T> void register(Class<? super T> clazz, T object)
Injectorpublic void provide(Class<? extends Annotation> clazz, Object object)
Injectorpublic <T> T getSingleton(Class<T> clazz)
InjectorgetSingleton in interface InjectorT - the class' typeclazz - the class to retrieve the value forpublic <T> T newInstance(Class<T> clazz)
InjectornewInstance in interface InjectorT - the class' typeclazz - the class to instantiatepublic <T> T getIfAvailable(Class<T> clazz)
Injectornull. Calling this method will never create any new objects.getIfAvailable in interface InjectorT - the class' typeclazz - the class to retrieve the instance forpublic <T> T createIfHasDependencies(Class<T> clazz)
InjectorNote: Currently, all dependencies of the class need to be registered singletons for a new instance to be created. This limitation may be lifted in future versions.
createIfHasDependencies in interface InjectorT - the class' typeclazz - the class to construct if possiblenull if any dependency does not already existpublic <T> Collection<T> retrieveAllOfType(Class<T> clazz)
InjectorObject as clazz will return all known singletons.retrieveAllOfType in interface InjectorT - the class' typeclazz - the class to retrieve singletons ofpublic <T> void registerProvider(Class<T> clazz, javax.inject.Provider<? extends T> provider)
InjectorregisterProvider in interface InjectorT - the class' typeclazz - the class to register the provider forprovider - the providerpublic <T,P extends javax.inject.Provider<? extends T>> void registerProvider(Class<T> clazz, Class<P> providerClass)
Injectorclazz has to
be instantiated, the providerClass will be instantiated.registerProvider in interface InjectorT - the class' typeP - the provider's typeclazz - the class to register the provider forproviderClass - the class of the providerpublic InjectorConfig getConfig()
@Nullable protected Object resolveContext(ResolutionContext context)
context - the context to resolve the object fornull if the context specifies it is optional and some criteria is not metprotected Object[] resolveDependencies(ResolutionContext context, Resolution<?> resolution)
null, the process is aborted and the remaining dependencies
are not resolved.context - the resolution contextresolution - the resolution whose dependencies should be providedprotected void throwForUnexpectedNullDependency(ResolutionContext context)
resolveContext(ch.jalu.injector.context.ResolutionContext).context - the resolution contextprotected Resolution<?> findResolutionOrFail(ResolutionContext context)
Resolution that is returned based on
the provided resolution context. Throws an exception if no handler returned a resolution.context - the context to find the resolution forprotected <T> T runPostConstructHandlers(T instance,
ResolutionContext context,
Resolution<?> resolution)
T - the object's typeinstance - the object that was resolvedcontext - the resolution contextresolution - the resolution used to get the objectCopyright © 2017. All rights reserved.