3.6 KiB
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 core kernel infrastructure services only (no business logic services) with proper lifecycle management, dependency resolution, and service override support.
Description
This story extends the basic DI container to support core kernel services only: config, logger, health checks, metrics, error bus, observability, and service registry. The container must handle service initialization order, lifecycle management, and provide a clean way to override services for testing.
Note: Business services (Auth, Identity, Authz, Audit) are NOT in the core kernel. They are separate services implemented in Epic 2.
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 core kernel services only:
ProvideConfig() fx.Option- Configuration providerProvideLogger() fx.Option- Logger providerProvideHealthCheckers() fx.Option- Health check registry providerProvideMetrics() fx.Option- Prometheus metrics registry providerProvideErrorBus() fx.Option- Error bus providerProvideTracer() fx.Option- OpenTelemetry tracer providerProvideServiceRegistry() fx.Option- Service registry provider (Consul)
Note: Database provider is NOT in core kernel - each service will create its own database client.
3. Core Module (internal/di/core_module.go)
- Export
CoreModule() fx.Optionthat provides all core services - Easy composition with future modules
- Single import point for core services
Implementation Steps
-
Extend Container
- Update
internal/di/container.go - Add support for all core services
- Implement lifecycle hooks
- Update
-
Create Provider Functions
- Create
internal/di/providers.go - Implement all provider functions
- Handle dependencies correctly
- Create
-
Create Core Module
- Create
internal/di/core_module.go - Export CoreModule function
- Document usage
- Create
-
Test Integration
- Verify all services are provided
- Test service overrides
- Test lifecycle hooks
Acceptance Criteria
- All core kernel services are provided via DI container
- Services are initialized in correct dependency order
- Lifecycle hooks work for all services
- Services can be overridden for testing
- DI container compiles without errors
- CoreModule can be imported and used
- Error handling works during initialization
- No business logic services in core kernel
- Service registry provider is included
Related ADRs
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
# 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 containerinternal/di/providers.go- Provider functionsinternal/di/core_module.go- Core module export