You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extract duplicated validation and error handling patterns from service_container.h into reusable helper methods to reduce code duplication and improve maintainability.
Background (Why)
The same validation patterns (freeze check, lock acquisition, already-registered check) are repeated in multiple registration methods
Factory exception handling with error wrapping is duplicated in singleton, transient, and scoped resolution branches
Audit logging calls follow the same pattern in multiple locations
Violates DRY principle - Kent Beck's "No Duplication" rule
File is 745 lines; extracting common patterns will improve readability
Scope (What)
Current State (Duplicated Patterns)
Pattern 1: Registration Validation (repeated in register_factory_internal and register_instance_internal)
VoidResult service_container::register_factory_internal(...) {
auto validation = validate_registration(interface_type, type_name);
if (!validation.is_ok()) return validation;
std::unique_lock lock(mutex_);
// ... rest of registration
}
// In resolve_with_detection:case service_lifetime::singleton: {
if (entry.is_instantiated) {
return Result<std::shared_ptr<void>>::ok(entry.singleton_instance);
}
read_lock.unlock();
auto result = invoke_factory_safe(factory_copy);
if (!result.is_ok()) return result;
// ... store instance
}
Impact Analysis (Where)
Location
Lines
Duplicated Pattern
register_factory_internal
368-410
Validation + audit logging
register_instance_internal
413-461
Validation + audit logging
resolve_with_detection
527-535
Factory exception handling
resolve_with_detection
556-564
Factory exception handling
resolve_with_detection
586-594
Factory exception handling
Estimated duplication: ~80 lines of duplicated patterns
Summary
Extract duplicated validation and error handling patterns from
service_container.hinto reusable helper methods to reduce code duplication and improve maintainability.Background (Why)
Scope (What)
Current State (Duplicated Patterns)
Pattern 1: Registration Validation (repeated in
register_factory_internalandregister_instance_internal)Pattern 2: Factory Exception Handling (repeated 3 times in
resolve_with_detection)Proposed State
Simplified usage:
Impact Analysis (Where)
register_factory_internalregister_instance_internalresolve_with_detectionresolve_with_detectionresolve_with_detectionEstimated duplication: ~80 lines of duplicated patterns
Implementation Plan (How)
validate_registration()private helper methodinvoke_factory_safe()private helper methodlog_registration_failure()private helper methodregister_factory_internal()to use helpersregister_instance_internal()to use helpersinvoke_factory_safe()invoke_factory_safe()invoke_factory_safe()Acceptance Criteria
Labels
refactorcode-qualityduplication