Class BringApplicationContext

All Implemented Interfaces:
BeanDefinitionRegistry, BeanRegistry, BringBeanFactory

public class BringApplicationContext extends AnnotationBringBeanRegistry implements BringBeanFactory
The BringApplicationContext class represents the core context for managing and initializing the Bring application's beans. It extends AnnotationBringBeanRegistry to provide bean registration capabilities based on annotations and implements BringBeanFactory to define bean creation methods.

The class is initialized with a base package for component scanning, and it performs the following steps:

  1. Uses Reflections to scan the specified base package for classes with relevant annotations.
  2. Creates a ClassPathScannerFactory to obtain a set of classes marked for bean creation.
  3. Creates a BeanPostProcessorDefinitionFactory to handle bean post-processor definitions.
  4. Registers Bean definitions for classes annotated with annotations from the classpath scan.
  5. Creates a BeanPostProcessorFactory to handle bean post-processors.

The class maintains the following important fields:

  • classPathScannerFactory: Factory for creating a class path scanner for component scanning.
  • beanPostProcessorFactory: Factory for creating bean post-processors.
  • beanPostProcessorDefinitionFactory: Factory for handling bean post-processor definitions.
  • beansToCreate: Set of classes annotated for bean creation obtained from the class path scanner.

Usage example:


 BringApplicationContext context = new BringApplicationContext("com.example.myapp");
 
Since:
1.0
Author:
Blyzhnytsia Team
See Also:
  • Field Details

  • Constructor Details

    • BringApplicationContext

      public BringApplicationContext(String... basePackage)
      Constructs a new BringApplicationContext with the specified base package for component scanning.
      Parameters:
      basePackage - the base package to scan for annotated beans
      See Also:
    • BringApplicationContext

      public BringApplicationContext(Class<T> componentClass)
      Constructs a BringApplicationContext for the specified component class package.
      Type Parameters:
      T - The type of the component class.
      Parameters:
      componentClass - The class used to determine the package for component scanning.
  • Method Details

    • register

      private void register(Set<Class<?>> classes)
      Registers the provided classes as bean definitions within the context. Creates a BeanDefinition for each class and registers it in the context.
      Parameters:
      classes - The set of classes to be registered as bean definitions.
    • refresh

      public void refresh()
      Refreshes the application context, creating additional Bean definitions, instantiating Singleton Beans, and invoking BeanPostProcessors to process beans during initialization.
    • invokeBeanFactoryPostProcessors

      private void invokeBeanFactoryPostProcessors()
      Invokes the registered BeanFactoryPostProcessors to perform any necessary operations on the BeanFactory. Additionally, sets up the TypeResolverFactory for resolving types within the context.
    • invokeBeanPostProcessors

      private void invokeBeanPostProcessors()
      Invokes registered BeanPostProcessors to process bean initialization within the context. Each bean is processed by the available BeanPostProcessors.
    • instantiateBeans

      private void instantiateBeans()
      Instantiates beans based on their definitions within the context. Beans are registered and created according to their definitions.