Commit d28af64
User
feat(high): Implement Dependency Injection container for better testability
Added comprehensive DI container:
- DIContainer class with lazy initialization for all components
- Protocol-based interfaces for better abstraction
- Singleton pattern for shared resources (cache, circuit breaker, etc.)
- Property-based access with setters for testing
- Global container management (get_container, set_container, reset_container)
Benefits:
- Easy mocking for unit tests (inject mock implementations)
- Clear dependency graph and reduced coupling
- Centralized lifecycle management (initialize/shutdown)
- Better testability with isolated test containers
- Backward compatible with existing code
Updated ErniPhotoAgency:
- Now accepts optional DIContainer in constructor
- Uses container for all component access
- Simplified initialization (delegates to container)
- Added shutdown() method for graceful cleanup
Updated FastAPI lifespan:
- Initialize global DI container on startup
- Proper shutdown sequence for all components
- Improved error messages for uninitialized state
Tests:
- 20 comprehensive unit tests for DI container
- Test lazy initialization, lifecycle, and mocking
- All tests passing
Resolves: openai#2 (HIGH priority)
Impact: Significantly improves code testability and maintainability1 parent 980bcda commit d28af64
File tree
3 files changed
+2853
-0
lines changed- examples/erni-foto-agency
- erni_foto_agency
- tests/unit
3 files changed
+2853
-0
lines changed
0 commit comments