Class BringApplicationContext
java.lang.Object
com.bobocode.bring.core.context.impl.DefaultBringBeanFactory
com.bobocode.bring.core.context.impl.AnnotationBringBeanRegistry
com.bobocode.bring.core.context.impl.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:
- Uses
Reflectionsto scan the specified base package for classes with relevant annotations. - Creates a
ClassPathScannerFactoryto obtain a set of classes marked for bean creation. - Creates a
BeanPostProcessorDefinitionFactoryto handle bean post-processor definitions. - Registers Bean definitions for classes annotated with annotations from the classpath scan.
- Creates a
BeanPostProcessorFactoryto 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 Summary
FieldsFields inherited from class com.bobocode.bring.core.context.impl.AnnotationBringBeanRegistry
classPathScannerFactory -
Constructor Summary
ConstructorsConstructorDescriptionBringApplicationContext(Class<T> componentClass) Constructs a BringApplicationContext for the specified component class package.BringApplicationContext(String... basePackage) Constructs a new BringApplicationContext with the specified base package for component scanning. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidInstantiates beans based on their definitions within the context.private voidInvokes the registered BeanFactoryPostProcessors to perform any necessary operations on the BeanFactory.private voidInvokes registered BeanPostProcessors to process bean initialization within the context.voidrefresh()Refreshes the application context, creating additional Bean definitions, instantiating Singleton Beans, and invoking BeanPostProcessors to process beans during initialization.private voidRegisters the provided classes as bean definitions within the context.Methods inherited from class com.bobocode.bring.core.context.impl.AnnotationBringBeanRegistry
getOrCreateBean, registerBean, registerBeanDefinitionMethods inherited from class com.bobocode.bring.core.context.impl.DefaultBringBeanFactory
addBeanDefinition, addPrototypeBean, addSingletonBean, close, getAllBeanDefinitionNames, getAllBeans, getBean, getBean, getBeanByName, getBeanDefinitionByName, getBeans, isBeanCreatedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.bobocode.bring.core.context.BringBeanFactory
close, getAllBeans, getBean, getBean, getBeans
-
Field Details
-
beanPostProcessorDefinitionFactory
-
-
Constructor Details
-
BringApplicationContext
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
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
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.
-