dependency_container
¶
Dependency Injection Container Module.
Manages the lifecycle and dependency relationships between application services. Centralizes service initialization, configuration, and proper shutdown procedures. Provides access to configured service instances including loggers, analytics, API clients, and core application components. Handles circular imports and asynchronous resource management.
InitializableService
¶
Bases: Protocol
Protocol for services that can be initialized.
Note: Services may have different initialize signatures, handled dynamically by _initialize_service method.
DependencyContainer
¶
DependencyContainer(
config_path,
console_logger,
error_logger,
analytics_logger,
db_verify_logger,
*,
logging_listener=None,
dry_run=False,
skip_api_validation=False
)
Dependency injection container for the application.
This class manages the lifecycle and dependencies of all services in the application.
Initialize the dependency container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str
|
Path to the configuration file |
required |
console_logger
|
Logger
|
Logger for console output |
required |
error_logger
|
Logger
|
Logger for error messages |
required |
analytics_logger
|
Logger
|
Logger for analytics events |
required |
db_verify_logger
|
Logger
|
Logger for database verification operations |
required |
logging_listener
|
SafeQueueListener | None
|
Optional queue listener for logging |
None
|
dry_run
|
bool
|
Whether to run in dry-run mode (no changes made) |
False
|
skip_api_validation
|
bool
|
Whether to skip API auth validation (for non-API commands) |
False
|
Source code in src/services/dependency_container.py
cache_service
property
¶
Initialized cache orchestrator; raises if not yet initialized.
library_snapshot_service
property
¶
Initialized snapshot service; raises if not yet initialized.
pending_verification_service
property
¶
Initialized verification service; raises if not yet initialized.
external_api_service
property
¶
Initialized API orchestrator; raises if not yet initialized.
initialize
async
¶
Initialize all services with async setup requirements.
Source code in src/services/dependency_container.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
get_analytics
¶
Return the initialized analytics tracker; raises if not yet initialized.
Source code in src/services/dependency_container.py
get_error_logger
¶
get_console_logger
¶
close
async
¶
Close all services in the correct order.
Order: API first (to flush pending tasks), then cache (to persist data). This prevents API orchestrator from writing to a closed cache during shutdown.
Source code in src/services/dependency_container.py
shutdown
¶
Clean up non-async resources and stop services.