Class InjectionFramework
java.lang.Object
build.codemodel.dependency.injection.InjectionFramework
A
JDKCodeModel-based Adapter allowing the
runtime discovery of InjectionPoints and JSR-330-compliant
Dependency Injection of Classes
and Objects- Since:
- Oct-2024
- Author:
- brian.oliver
-
Constructor Summary
ConstructorsConstructorDescriptionInjectionFramework(build.codemodel.jdk.JDKCodeModel codeModel) Constructs anInjectionFramework. -
Method Summary
Modifier and TypeMethodDescriptionvoidbindScope(Class<? extends Annotation> scopeAnnotation, Scope scope) Registers aScopeimplementation for the specified scope annotation type.build.codemodel.jdk.JDKCodeModelObtains theJDKCodeModelused byInjectionFramework.static InjectionFrameworkcreate()Creates anInjectionFrameworkwith a default non-cachingJDKCodeModel.findScope(build.codemodel.jdk.descriptor.JDKTypeDescriptor typeDescriptor) Returns the registeredScopefor the givenJDKTypeDescriptor, if the type carries a scope annotation that has been registered viabindScope(Class, Scope).Optional<Map.Entry<Class<? extends Annotation>, Scope>> findScopeEntry(build.codemodel.jdk.descriptor.JDKTypeDescriptor typeDescriptor) Returns the registered scope entry (annotation class +Scope) for the givenJDKTypeDescriptor, if the type carries a scope annotation that has been registered viabindScope(Class, Scope).getInjectableDescriptor(build.codemodel.jdk.descriptor.JDKTypeDescriptor typeDescriptor) Obtains theInjectableDescriptorfor the specifiedJDKTypeDescriptor, using theJDKTypeDescriptorif necessary to establish one.getInjectableDescriptor(Class<?> injectableClass) Obtains theInjectableDescriptorfor the specifiedClass, using theJDKCodeModelif necessary to establish one.Stream<build.codemodel.foundation.usage.AnnotationTypeUsage> getQualifierAnnotationTypes(build.codemodel.foundation.descriptor.Traitable traitable) Determines theAnnotationTypeUsages of the specifiedTraitablethat have theQualifiermeta-annotation.booleanhasQualifierAnnotation(build.codemodel.jdk.descriptor.JDKTypeDescriptor annotationTypeDescriptor) Determines if the specifiedJDKTypeDescriptor, usually for anAnnotation, is annotated withQualifier.booleanisInjectionPoint(build.codemodel.foundation.descriptor.Traitable traitable) Determines if aTraitablerepresents anInjectionPoint, which means it is non-static, non-abstractwith anAnnotationTypeUsageforInject.booleanisPostInject(build.codemodel.objectoriented.descriptor.MethodDescriptor descriptor) Determines if aMethodDescriptorrepresents anPostInjectmethod, which means it is non-static, non-abstractwith anAnnotationTypeUsageforPostInject.booleanisPreDestroy(build.codemodel.objectoriented.descriptor.MethodDescriptor descriptor) Determines if aMethodDescriptorrepresents aPreDestroymethod.booleanisProvides(build.codemodel.objectoriented.descriptor.MethodDescriptor descriptor) booleanisSingleton(build.codemodel.jdk.descriptor.JDKTypeDescriptor typeDescriptor) Determines if the specifiedJDKTypeDescriptoris annotated as aSingleton.Creates a new emptyContext.newContext(Module... modules) newContext(Resolver<?>... resolvers) voidsetBindingGraphContributor(BindingGraphContributor contributor) Installs aBindingGraphContributorthat will be notified of every binding registration and dependency resolution for all contexts created by this framework.Installs aGraphBuildingContributorand returns this framework for fluent chaining.
-
Constructor Details
-
InjectionFramework
public InjectionFramework(build.codemodel.jdk.JDKCodeModel codeModel) Constructs anInjectionFramework.- Parameters:
codeModel- theJDKCodeModel
-
-
Method Details
-
create
Creates anInjectionFrameworkwith a default non-cachingJDKCodeModel.- Returns:
- a new
InjectionFramework
-
codeModel
public build.codemodel.jdk.JDKCodeModel codeModel()Obtains theJDKCodeModelused byInjectionFramework.- Returns:
- the
JDKCodeModel
-
hasQualifierAnnotation
public boolean hasQualifierAnnotation(build.codemodel.jdk.descriptor.JDKTypeDescriptor annotationTypeDescriptor) Determines if the specifiedJDKTypeDescriptor, usually for anAnnotation, is annotated withQualifier.- Parameters:
annotationTypeDescriptor- theJDKTypeDescriptor- Returns:
trueif theJDKTypeDescriptorhas aQualifierannotation,falseotherwise
-
getQualifierAnnotationTypes
public Stream<build.codemodel.foundation.usage.AnnotationTypeUsage> getQualifierAnnotationTypes(build.codemodel.foundation.descriptor.Traitable traitable) Determines theAnnotationTypeUsages of the specifiedTraitablethat have theQualifiermeta-annotation.- Parameters:
traitable-Traitable- Returns:
- the
StreamofQualifierAnnotationTypeUsages
-
getInjectableDescriptor
Obtains theInjectableDescriptorfor the specifiedClass, using theJDKCodeModelif necessary to establish one.- Parameters:
injectableClass- theClass- Returns:
- the
InjectableDescriptorfor theClass
-
getInjectableDescriptor
public InjectableDescriptor getInjectableDescriptor(build.codemodel.jdk.descriptor.JDKTypeDescriptor typeDescriptor) Obtains theInjectableDescriptorfor the specifiedJDKTypeDescriptor, using theJDKTypeDescriptorif necessary to establish one.- Parameters:
typeDescriptor- theJDKTypeDescriptor- Returns:
- the
InjectableDescriptorfor theJDKTypeDescriptor
-
isInjectionPoint
public boolean isInjectionPoint(build.codemodel.foundation.descriptor.Traitable traitable) Determines if aTraitablerepresents anInjectionPoint, which means it is non-static, non-abstractwith anAnnotationTypeUsageforInject.- Parameters:
traitable- theTraitable- Returns:
trueif theTraitablecontains anInjectuse,falseotherwise
-
isSingleton
public boolean isSingleton(build.codemodel.jdk.descriptor.JDKTypeDescriptor typeDescriptor) Determines if the specifiedJDKTypeDescriptoris annotated as aSingleton.- Parameters:
typeDescriptor- theJDKTypeDescriptor- Returns:
trueif annotated as aSingleton, otherwisefalse
-
isPostInject
public boolean isPostInject(build.codemodel.objectoriented.descriptor.MethodDescriptor descriptor) Determines if aMethodDescriptorrepresents anPostInjectmethod, which means it is non-static, non-abstractwith anAnnotationTypeUsageforPostInject.- Parameters:
descriptor- theMethodDescriptor- Returns:
trueif theTraitablecontains anInjectuse,falseotherwise
-
isPreDestroy
public boolean isPreDestroy(build.codemodel.objectoriented.descriptor.MethodDescriptor descriptor) Determines if aMethodDescriptorrepresents aPreDestroymethod.- Parameters:
descriptor- theMethodDescriptor- Returns:
trueif annotated withPreDestroy
-
bindScope
Registers aScopeimplementation for the specified scope annotation type. The scope is applied whenever a class annotated withscopeAnnotationis bound viaBinder.bind(Class).- Parameters:
scopeAnnotation- the scope annotation class (must be annotated withScopeAnnotation)scope- theScopeimplementation to register
-
findScopeEntry
public Optional<Map.Entry<Class<? extends Annotation>, Scope>> findScopeEntry(build.codemodel.jdk.descriptor.JDKTypeDescriptor typeDescriptor) Returns the registered scope entry (annotation class +Scope) for the givenJDKTypeDescriptor, if the type carries a scope annotation that has been registered viabindScope(Class, Scope).- Parameters:
typeDescriptor- the type descriptor to inspect- Returns:
- an
Optionalcontaining the matching entry, or empty if none
-
findScope
Returns the registeredScopefor the givenJDKTypeDescriptor, if the type carries a scope annotation that has been registered viabindScope(Class, Scope). -
withBindingGraph
Installs aGraphBuildingContributorand returns this framework for fluent chaining. Every context created by this framework will contribute its bindings and resolved dependencies to the graph, which can then be snapshotted viaContext.snapshot(Path).- Returns:
- this
InjectionFramework
-
setBindingGraphContributor
Installs aBindingGraphContributorthat will be notified of every binding registration and dependency resolution for all contexts created by this framework. Replaces the defaultBindingGraphContributor.NOOP.- Parameters:
contributor- the contributor to install; must not benull
-
isProvides
public boolean isProvides(build.codemodel.objectoriented.descriptor.MethodDescriptor descriptor) Determines if aMethodDescriptorrepresents aProvidesmethod, which means it is non-static, non-abstract, non-voidwith anAnnotationTypeUsageforProvides.This is a descriptor-level predicate intended for use when scanning a
JDKTypeDescriptorto identify provider methods before constructing aProvidesResolver.- Parameters:
descriptor- theMethodDescriptor- Returns:
trueif theMethodDescriptorhas aProvidesannotation,falseotherwise
-
newContext
-
newContext
-
newContext
-