- 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
3.8 KiB
3.8 KiB
Story 0.5: Dependency Injection and Application Bootstrap
Metadata
- Story ID: 0.5
- Title: Dependency Injection and Application Bootstrap
- Epic: 0 - Project Setup & Foundation
- Status: Completed
- Priority: High
- Estimated Time: 4-5 hours
- Dependencies: 0.1, 0.2, 0.3
Goal
Set up dependency injection container using Uber FX and create the application entry point that initializes the platform with proper lifecycle management.
Description
This story implements the dependency injection system using Uber FX and creates the main application entry point. The DI container will manage service lifecycle, dependencies, and provide a clean way to wire services together.
Deliverables
1. DI Container (internal/di/container.go)
FX-based dependency injection container:
- Initialize FX container
- Register Config and Logger providers
- Basic lifecycle hooks (OnStart, OnStop)
- Support service overrides for testing
- Graceful shutdown handling
2. DI Providers (internal/di/providers.go)
Provider functions for core services:
ProvideConfig() fx.Option- Configuration providerProvideLogger() fx.Option- Logger provider- Provider functions return FX options for easy composition
3. Application Entry Point (cmd/platform/main.go)
Main application bootstrap:
- Load configuration
- Initialize DI container with core services
- Set up basic application lifecycle
- Start minimal HTTP server (placeholder for Epic 1)
- Handle graceful shutdown (SIGINT, SIGTERM)
- Proper error handling and logging
4. Core Module (internal/di/core_module.go)
Optional: Export core module as FX option:
CoreModule() fx.Option- Provides all core services- Easy to compose with future modules
Implementation Steps
-
Install Dependencies
go get go.uber.org/fx@latest -
Create DI Container
- Create
internal/di/container.go - Initialize FX app
- Set up lifecycle hooks
- Add graceful shutdown
- Create
-
Create Provider Functions
- Create
internal/di/providers.go - Implement
ProvideConfig()function - Implement
ProvideLogger()function - Return FX options
- Create
-
Create Application Entry Point
- Create
cmd/platform/main.go - Load configuration
- Initialize FX app with providers
- Set up signal handling
- Start minimal server (placeholder)
- Handle shutdown gracefully
- Create
-
Test Application
- Verify application starts
- Verify graceful shutdown works
- Test service injection
Acceptance Criteria
- DI container initializes successfully
- Config and Logger are provided via DI
- Application starts and runs
- Application shuts down gracefully on signals
- Lifecycle hooks work correctly
- Services can be overridden for testing
- Application compiles and runs successfully
- Error handling is comprehensive
- Logging works during startup/shutdown
Related ADRs
Implementation Notes
- Use FX for dependency injection and lifecycle management
- Support graceful shutdown with context cancellation
- Handle SIGINT and SIGTERM signals
- Log startup and shutdown events
- Make services easily testable via interfaces
- Consider adding health check endpoint in future
- Support for service overrides is important for testing
Testing
# Test application startup
go run cmd/platform/main.go
# Test graceful shutdown
# Start app, then send SIGTERM
kill -TERM <pid>
# Test DI container
go test ./internal/di/...
Files to Create/Modify
internal/di/container.go- DI containerinternal/di/providers.go- Provider functionsinternal/di/core_module.go- Core module (optional)cmd/platform/main.go- Application entry pointgo.mod- Add FX dependency