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:
  1. Registering beans by bean name and bean definition: The bean name is created using AnnotationResolver and is the key of the DefaultBringBeanFactory.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.
  2. 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 Details

    • classPathScannerFactory

      protected ClassPathScannerFactory classPathScannerFactory
    • beanCreator

      private final BeanCreator beanCreator
    • currentlyCreatingBeans

      private final Set<String> currentlyCreatingBeans
    • reflections

      private final org.reflections.Reflections reflections
  • Constructor Details

    • AnnotationBringBeanRegistry

      public AnnotationBringBeanRegistry(org.reflections.Reflections reflections)
  • Method Details

    • registerBean

      public void registerBean(String beanName, BeanDefinition beanDefinition)
      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 interface BeanRegistry
      Parameters:
      beanName - The name of the bean to be registered.
      beanDefinition - The definition of the bean being registered.
    • registerBeanDefinition

      public void registerBeanDefinition(BeanDefinition beanDefinition)
      Stores a bean definition into DefaultBringBeanFactory.beanDefinitionMap by a name generated via AnnotationResolver. Beans are created based on these bean definitions.
      Specified by:
      registerBeanDefinition in interface BeanDefinitionRegistry
      Parameters:
      beanDefinition - The definition of the bean to be registered.
    • getOrCreateBean

      public Object getOrCreateBean(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.
      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.