@@ -54,32 +54,32 @@ class ApplicationContextView(BaseModel):
54
54
"""View model for application context state."""
55
55
56
56
config : ApplicationContextConfig
57
- component_cls_container : list [str ]
58
- singleton_component_instance_container : list [str ]
57
+ component_classes : list [str ]
58
+ component_instances : list [str ]
59
59
60
60
61
61
class ContainerManager :
62
62
"""Manages containers for different types of entities in the application context."""
63
63
64
64
def __init__ (self ):
65
- self .component_cls_container : dict [str , Type [Component ]] = {}
66
- self .controller_cls_container : dict [str , Type [RestController ]] = {}
67
- self .singleton_component_instance_container : dict [str , Component ] = {}
65
+ self .component_classes : dict [str , Type [Component ]] = {}
66
+ self .controller_classes : dict [str , Type [RestController ]] = {}
67
+ self .component_instances : dict [str , Component ] = {}
68
68
69
- self .bean_collection_cls_container : dict [str , Type [BeanCollection ]] = {}
70
- self .singleton_bean_instance_container : dict [str , object ] = {}
69
+ self .bean_collection_classes : dict [str , Type [BeanCollection ]] = {}
70
+ self .bean_instances : dict [str , object ] = {}
71
71
72
- self .properties_cls_container : dict [str , Type [Properties ]] = {}
73
- self .singleton_properties_instance_container : dict [str , Properties ] = {}
72
+ self .properties_classes : dict [str , Type [Properties ]] = {}
73
+ self .properties_instances : dict [str , Properties ] = {}
74
74
75
75
def is_entity_in_container (self , entity_cls : Type [AppEntities ]) -> bool :
76
76
"""Check if an entity class is registered in any container."""
77
77
cls_name = entity_cls .__name__
78
78
return (
79
- cls_name in self .component_cls_container
80
- or cls_name in self .controller_cls_container
81
- or cls_name in self .bean_collection_cls_container
82
- or cls_name in self .properties_cls_container
79
+ cls_name in self .component_classes
80
+ or cls_name in self .controller_classes
81
+ or cls_name in self .bean_collection_classes
82
+ or cls_name in self .properties_classes
83
83
)
84
84
85
85
@@ -241,7 +241,7 @@ def register_component(self, component_cls: Type[Component]) -> None:
241
241
)
242
242
243
243
component_cls_name = component_cls .get_name ()
244
- existing_component = self .container_manager .component_cls_container .get (
244
+ existing_component = self .container_manager .component_classes .get (
245
245
component_cls_name
246
246
)
247
247
@@ -253,7 +253,7 @@ def register_component(self, component_cls: Type[Component]) -> None:
253
253
):
254
254
return
255
255
256
- self .container_manager .component_cls_container [component_cls_name ] = (
256
+ self .container_manager .component_classes [component_cls_name ] = (
257
257
component_cls
258
258
)
259
259
@@ -266,15 +266,15 @@ def get_component(
266
266
267
267
target_cls_name = self ._determine_target_cls_name (component_cls , qualifier )
268
268
269
- if target_cls_name not in self .container_manager .component_cls_container :
269
+ if target_cls_name not in self .container_manager .component_classes :
270
270
return None
271
271
272
272
scope = component_cls .get_scope ()
273
273
match scope :
274
274
case ComponentScope .Singleton :
275
275
return cast (
276
276
T ,
277
- self .container_manager .singleton_component_instance_container .get (
277
+ self .container_manager .component_instances .get (
278
278
target_cls_name
279
279
),
280
280
)
@@ -340,7 +340,7 @@ def _init_abstract_component_subclasses(self, component_cls: Type[ABC]) -> None:
340
340
subclass_component_cls , subclass_component_cls .get_name ()
341
341
)
342
342
if instance is not None :
343
- self .container_manager .singleton_component_instance_container [
343
+ self .container_manager .component_instances [
344
344
subclass_component_cls .get_name ()
345
345
] = instance
346
346
@@ -349,7 +349,7 @@ def init_singleton_components(self) -> None:
349
349
for (
350
350
component_cls_name ,
351
351
component_cls ,
352
- ) in self .container_manager .component_cls_container .items ():
352
+ ) in self .container_manager .component_classes .items ():
353
353
if component_cls .get_scope () != ComponentScope .Singleton :
354
354
continue
355
355
@@ -364,7 +364,7 @@ def init_singleton_components(self) -> None:
364
364
component_cls , component_cls_name
365
365
)
366
366
if instance is not None :
367
- self .container_manager .singleton_component_instance_container [
367
+ self .container_manager .component_instances [
368
368
component_cls_name
369
369
] = instance
370
370
@@ -389,18 +389,18 @@ def register_bean_collection(self, bean_cls: Type[BeanCollection]) -> None:
389
389
)
390
390
391
391
bean_name = bean_cls .get_name ()
392
- self .container_manager .bean_collection_cls_container [bean_name ] = bean_cls
392
+ self .container_manager .bean_collection_classes [bean_name ] = bean_cls
393
393
394
394
def get_bean (
395
395
self , object_cls : Type [T ], qualifier : Optional [str ] = None
396
396
) -> Optional [T ]:
397
397
"""Get a bean instance by class and optional qualifier."""
398
398
bean_name = object_cls .__name__
399
- if bean_name not in self .container_manager .singleton_bean_instance_container :
399
+ if bean_name not in self .container_manager .bean_instances :
400
400
return None
401
401
402
402
return cast (
403
- T , self .container_manager .singleton_bean_instance_container .get (bean_name )
403
+ T , self .container_manager .bean_instances .get (bean_name )
404
404
)
405
405
406
406
def _inject_bean_collection_dependencies (
@@ -414,7 +414,7 @@ def _inject_bean_collection_dependencies(
414
414
415
415
def _validate_bean_view (self , view : BeanView , collection_name : str ) -> None :
416
416
"""Validate a bean view before adding it to the container."""
417
- if view .bean_name in self .container_manager .singleton_bean_instance_container :
417
+ if view .bean_name in self .container_manager .bean_instances :
418
418
raise BeanConflictError (
419
419
f"[BEAN CONFLICTS] Bean: { view .bean_name } already exists under collection: { collection_name } "
420
420
)
@@ -430,7 +430,7 @@ def init_singleton_beans(self) -> None:
430
430
for (
431
431
bean_collection_cls_name ,
432
432
bean_collection_cls ,
433
- ) in self .container_manager .bean_collection_cls_container .items ():
433
+ ) in self .container_manager .bean_collection_classes .items ():
434
434
logger .debug (
435
435
f"[INITIALIZING SINGLETON BEAN] Init singleton bean: { bean_collection_cls_name } "
436
436
)
@@ -441,7 +441,7 @@ def init_singleton_beans(self) -> None:
441
441
bean_views = collection .scan_beans ()
442
442
for view in bean_views :
443
443
self ._validate_bean_view (view , collection .get_name ())
444
- self .container_manager .singleton_bean_instance_container [
444
+ self .container_manager .bean_instances [
445
445
view .bean_name
446
446
] = view .bean
447
447
@@ -464,19 +464,19 @@ def register_properties(self, properties_cls: Type[Properties]) -> None:
464
464
)
465
465
466
466
properties_name = properties_cls .get_key ()
467
- self .container_manager .properties_cls_container [properties_name ] = (
467
+ self .container_manager .properties_classes [properties_name ] = (
468
468
properties_cls
469
469
)
470
470
471
471
def get_properties (self , properties_cls : Type [PT ]) -> Optional [PT ]:
472
472
"""Get a properties instance by class."""
473
473
properties_cls_name = properties_cls .get_key ()
474
- if properties_cls_name not in self .container_manager .properties_cls_container :
474
+ if properties_cls_name not in self .container_manager .properties_classes :
475
475
return None
476
476
477
477
return cast (
478
478
PT ,
479
- self .container_manager .singleton_properties_instance_container .get (
479
+ self .container_manager .properties_instances .get (
480
480
properties_cls_name
481
481
),
482
482
)
@@ -485,7 +485,7 @@ def _create_properties_loader(self) -> _PropertiesLoader:
485
485
"""Create a properties loader instance."""
486
486
return _PropertiesLoader (
487
487
self .config .properties_path ,
488
- list (self .container_manager .properties_cls_container .values ()),
488
+ list (self .container_manager .properties_classes .values ()),
489
489
)
490
490
491
491
def load_properties (self ) -> None :
@@ -496,10 +496,10 @@ def load_properties(self) -> None:
496
496
for (
497
497
properties_key ,
498
498
properties_cls ,
499
- ) in self .container_manager .properties_cls_container .items ():
499
+ ) in self .container_manager .properties_classes .items ():
500
500
if (
501
501
properties_key
502
- in self .container_manager .singleton_properties_instance_container
502
+ in self .container_manager .properties_instances
503
503
):
504
504
continue
505
505
@@ -515,13 +515,13 @@ def load_properties(self) -> None:
515
515
f"with key: { properties_cls .get_key ()} "
516
516
)
517
517
518
- self .container_manager .singleton_properties_instance_container [
518
+ self .container_manager .properties_instances [
519
519
properties_key
520
520
] = optional_properties
521
521
522
522
# Update the global properties loader reference
523
523
_PropertiesLoader .optional_loaded_properties = (
524
- self .container_manager .singleton_properties_instance_container
524
+ self .container_manager .properties_instances
525
525
)
526
526
527
527
@@ -565,11 +565,11 @@ def as_view(self) -> ApplicationContextView:
565
565
"""Create a view model of the application context state."""
566
566
return ApplicationContextView (
567
567
config = self .config ,
568
- component_cls_container = list (
569
- self .container_manager .component_cls_container .keys ()
568
+ component_classes = list (
569
+ self .container_manager .component_classes .keys ()
570
570
),
571
- singleton_component_instance_container = list (
572
- self .container_manager .singleton_component_instance_container .keys ()
571
+ component_instances = list (
572
+ self .container_manager .component_instances .keys ()
573
573
),
574
574
)
575
575
@@ -618,25 +618,25 @@ def register_controller(self, controller_cls: Type[RestController]) -> None:
618
618
)
619
619
620
620
controller_cls_name = controller_cls .get_name ()
621
- self .container_manager .controller_cls_container [controller_cls_name ] = (
621
+ self .container_manager .controller_classes [controller_cls_name ] = (
622
622
controller_cls
623
623
)
624
624
625
625
def get_controller_instances (self ) -> list [RestController ]:
626
626
"""Get all controller instances."""
627
627
return [
628
- cls () for cls in self .container_manager .controller_cls_container .values ()
628
+ cls () for cls in self .container_manager .controller_classes .values ()
629
629
]
630
630
631
631
def get_singleton_component_instances (self ) -> list [Component ]:
632
632
"""Get all singleton component instances."""
633
633
return list (
634
- self .container_manager .singleton_component_instance_container .values ()
634
+ self .container_manager .component_instances .values ()
635
635
)
636
636
637
637
def get_singleton_bean_instances (self ) -> list [object ]:
638
638
"""Get all singleton bean instances."""
639
- return list (self .container_manager .singleton_bean_instance_container .values ())
639
+ return list (self .container_manager .bean_instances .values ())
640
640
641
641
def is_within_context (self , entity_cls : Type [AppEntities ]) -> bool :
642
642
"""Check if an entity class is registered in the application context."""
@@ -663,8 +663,8 @@ def inject_dependencies_for_external_object(self, object: Type[Any]) -> None:
663
663
def inject_dependencies_for_app_entities (self ) -> None :
664
664
"""Inject dependencies for all registered app entities."""
665
665
containers : list [Mapping [str , Type [AppEntities ]]] = [
666
- self .container_manager .component_cls_container ,
667
- self .container_manager .controller_cls_container ,
666
+ self .container_manager .component_classes ,
667
+ self .container_manager .controller_classes ,
668
668
]
669
669
670
670
for container in containers :
0 commit comments