Class AnnotationBringBeanRegistry
java.lang.Object
com.bobocode.bring.core.context.impl.DefaultBringBeanFactory
com.bobocode.bring.core.context.impl.AnnotationBringBeanRegistry
- All Implemented Interfaces:
BeanDefinitionRegistry
,BeanRegistry
,BringBeanFactory
- Direct Known Subclasses:
BringApplicationContext
public class AnnotationBringBeanRegistry
extends DefaultBringBeanFactory
implements BeanRegistry, BeanDefinitionRegistry
Registry class responsible for:
- Registering beans by bean name and bean definition: The bean name is created using
AnnotationResolver
and is the key of theDefaultBringBeanFactory.beanDefinitionMap
. The bean definition contains all the necessary information that is needed to create a bean. Depending on the bean scope, an object or a supplier will be stored in the application context. - Registering bean definitions: storing bean definitions in
DefaultBringBeanFactory.beanDefinitionMap
. Those will be used in the future to create or retrieve beans.
- Since:
- 1.0
- Author:
- Blyzhnytsia Team
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BeanCreator
protected ClassPathScannerFactory
private final org.reflections.Reflections
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetOrCreateBean
(String beanName) Retrieves an existing bean with the given name from the container, or creates and registers a new bean if it doesn't exist.void
registerBean
(String beanName, BeanDefinition beanDefinition) Registers beans in the application context.void
registerBeanDefinition
(BeanDefinition beanDefinition) Stores a bean definition intoDefaultBringBeanFactory.beanDefinitionMap
by a name generated viaAnnotationResolver
.Methods inherited from class com.bobocode.bring.core.context.impl.DefaultBringBeanFactory
addBeanDefinition, addPrototypeBean, addSingletonBean, close, getAllBeanDefinitionNames, getAllBeans, getBean, getBean, getBeanByName, getBeanDefinitionByName, getBeans, isBeanCreated
-
Field Details
-
classPathScannerFactory
-
beanCreator
-
currentlyCreatingBeans
-
reflections
private final org.reflections.Reflections reflections
-
-
Constructor Details
-
AnnotationBringBeanRegistry
public AnnotationBringBeanRegistry(org.reflections.Reflections reflections)
-
-
Method Details
-
registerBean
Registers beans in the application context. Creates and stores singleton bean objects or suppliers for prototype beans. Also defines the proper way to create beans depending on the type of the bean (annotated class or configuration bean) and injects dependant beans.- Specified by:
registerBean
in interfaceBeanRegistry
- Parameters:
beanName
- The name of the bean to be registered.beanDefinition
- The definition of the bean being registered.
-
registerBeanDefinition
Stores a bean definition intoDefaultBringBeanFactory.beanDefinitionMap
by a name generated viaAnnotationResolver
. Beans are created based on these bean definitions.- Specified by:
registerBeanDefinition
in interfaceBeanDefinitionRegistry
- Parameters:
beanDefinition
- The definition of the bean to be registered.
-
getOrCreateBean
Retrieves an existing bean with the given name from the container, or creates and registers a new bean if it doesn't exist.- Parameters:
beanName
- The name of the bean to retrieve or create.- Returns:
- An instance of the requested bean. If the bean already exists, the existing instance is returned; otherwise, a new instance is created and returned.
-