- Verified all acceptance criteria for Stories 1.1-1.6 - Updated Status fields from Pending to Completed - Marked all acceptance criteria checkboxes as completed - All stories in Epic 1 are now fully implemented and verified
96 lines
3.1 KiB
Markdown
96 lines
3.1 KiB
Markdown
# Story 1.1: Enhanced Dependency Injection Container
|
|
|
|
## Metadata
|
|
- **Story ID**: 1.1
|
|
- **Title**: Enhanced Dependency Injection Container
|
|
- **Epic**: 1 - Core Kernel & Infrastructure
|
|
- **Status**: Completed
|
|
- **Priority**: High
|
|
- **Estimated Time**: 3-4 hours
|
|
- **Dependencies**: 0.5
|
|
|
|
## Goal
|
|
Extend the DI container to provide all core infrastructure services with proper lifecycle management, dependency resolution, and service override support.
|
|
|
|
## Description
|
|
This story extends the basic DI container to support all core services including database, health checks, metrics, and error bus. The container must handle service initialization order, lifecycle management, and provide a clean way to override services for testing.
|
|
|
|
## Deliverables
|
|
|
|
### 1. Extended DI Container (`internal/di/container.go`)
|
|
- Registration of all core services
|
|
- Lifecycle management via FX
|
|
- Service override support for testing
|
|
- Dependency resolution
|
|
- Error handling during initialization
|
|
|
|
### 2. Provider Functions (`internal/di/providers.go`)
|
|
Complete provider functions for all core services:
|
|
- `ProvideConfig() fx.Option` - Configuration provider
|
|
- `ProvideLogger() fx.Option` - Logger provider
|
|
- `ProvideDatabase() fx.Option` - Ent database client provider
|
|
- `ProvideHealthCheckers() fx.Option` - Health check registry provider
|
|
- `ProvideMetrics() fx.Option` - Prometheus metrics registry provider
|
|
- `ProvideErrorBus() fx.Option` - Error bus provider
|
|
|
|
### 3. Core Module (`internal/di/core_module.go`)
|
|
- Export `CoreModule() fx.Option` that provides all core services
|
|
- Easy composition with future modules
|
|
- Single import point for core services
|
|
|
|
## Implementation Steps
|
|
|
|
1. **Extend Container**
|
|
- Update `internal/di/container.go`
|
|
- Add support for all core services
|
|
- Implement lifecycle hooks
|
|
|
|
2. **Create Provider Functions**
|
|
- Create `internal/di/providers.go`
|
|
- Implement all provider functions
|
|
- Handle dependencies correctly
|
|
|
|
3. **Create Core Module**
|
|
- Create `internal/di/core_module.go`
|
|
- Export CoreModule function
|
|
- Document usage
|
|
|
|
4. **Test Integration**
|
|
- Verify all services are provided
|
|
- Test service overrides
|
|
- Test lifecycle hooks
|
|
|
|
## Acceptance Criteria
|
|
- [x] All core services are provided via DI container
|
|
- [x] Services are initialized in correct dependency order
|
|
- [x] Lifecycle hooks work for all services
|
|
- [x] Services can be overridden for testing
|
|
- [x] DI container compiles without errors
|
|
- [x] CoreModule can be imported and used
|
|
- [x] Error handling works during initialization
|
|
|
|
## Related ADRs
|
|
- [ADR-0003: Dependency Injection Framework](../../adr/0003-dependency-injection-framework.md)
|
|
|
|
## Implementation Notes
|
|
- Use FX's dependency injection features
|
|
- Ensure proper initialization order
|
|
- Support service overrides via FX options
|
|
- Handle errors gracefully during startup
|
|
- Document provider functions
|
|
|
|
## Testing
|
|
```bash
|
|
# Test DI container
|
|
go test ./internal/di/...
|
|
|
|
# Test service injection
|
|
go run cmd/platform/main.go
|
|
```
|
|
|
|
## Files to Create/Modify
|
|
- `internal/di/container.go` - Extended container
|
|
- `internal/di/providers.go` - Provider functions
|
|
- `internal/di/core_module.go` - Core module export
|
|
|