Skip to content

refactor(di): Phase 1+2 — audit DI containers and add module registrar support #366

Description

@kcenon

Background

Part of #363

Phase 1 (Audit) and Phase 2 (Enhancement) of the DI container consolidation effort.

Phase 1: Audit and Compatibility Analysis

Findings

System DI Implementation Status Migration Effort
common_system service_container Reference implementation N/A
monitoring_system service_registration.h adapter Already delegating to service_container Minimal (cleanup only)
logger_system lightweight_di_container + service_registration.h Dual: internal string-based DI + service_container bridge Medium
database_system database_coordinator + service_registration.h Lifecycle-driven coordinator + service_container bridge High

Feature Comparison

Feature service_container lightweight_di database_coordinator
Type-safe registration C++20 concepts Generic template N/A (hardcoded)
Lifetimes singleton/transient/scoped factory/singleton lifecycle-managed
Circular dependency detection Thread-local stack None N/A (fixed DAG)
Thread safety shared_mutex + DCL std::mutex Per-adapter mutexes
Container freezing Yes No No
Audit logging RegistryAuditLog No No
Scoped containers Yes No No
Global singleton Yes No No

Key Finding

service_container is already the most feature-complete implementation. No critical feature gaps identified. Each downstream system already has a service_registration.h adapter that bridges to service_container.

Phase 2: Enhance service_container

Enhancement: Module Registrar Support

Add a standardized ModuleRegistrar concept and dynamic module registration to unified_bootstrapper, replacing compile-time #ifdef guards with runtime module registration.

Changes:

  1. Add ModuleRegistrar concept to concepts/service.h
  2. Add register_module() and registered_modules() to unified_bootstrapper
  3. Add unit tests for module registration
  4. Update register_optional_services() to support dynamic module registration

Acceptance Criteria

  • Audit findings documented
  • ModuleRegistrar concept added with compile-time validation
  • unified_bootstrapper supports dynamic module registration
  • Unit tests for module registration pass
  • All existing tests pass
  • No regressions in CI

Metadata

Metadata

Assignees

Labels

architectureArchitectural changes and designrefactoringCode refactoring and improvements

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions