Skip to content

Conversation

@allisson
Copy link
Owner

Introduce a custom DI container in internal/app/ to centralize all application component initialization and wiring, following Clean Architecture principles and improving maintainability.

  • internal/app/di.go: Complete DI container implementation with lazy initialization, singleton pattern, and clean resource management

  • internal/app/di_test.go: Comprehensive test suite with 6 test cases

  • internal/app/README.md: Detailed documentation with examples and guides

  • REFACTORING_SUMMARY.md: Complete summary of refactoring changes

  • cmd/app/main.go: Simplified from 236 to 182 lines (-23%)

    • Removed manual dependency wiring from runServer() and runWorker()
    • Removed setupLogger() function (moved to container)
    • Replaced closeDB() with closeContainer()
    • All commands now use container pattern
  • README.md: Updated project documentation

    • Added DI container to features list
    • Updated project structure to include internal/app/
    • Added comprehensive DI container documentation section
    • Enhanced "Adding New Domains" guide with DI registration steps
  • Lazy Initialization: Components created only on first access

  • Singleton Pattern: Each component initialized once and reused

  • Thread-Safe: Using sync.Once for concurrent access safety

  • Error Handling: Comprehensive error propagation and storage

  • Resource Cleanup: Unified Shutdown() method for all resources

  • Testability: Easily testable and mockable for integration tests

  1. Centralized dependency management - all wiring in one place
  2. Simplified main.go - reduced complexity by 23%
  3. Eliminated duplicate initialization code across commands
  4. Improved testability with mockable container
  5. Better scalability - easy to add new domains
  6. Clean resource management with unified shutdown
  7. No external DI framework dependencies

…t management

Introduce a custom DI container in internal/app/ to centralize all
application component initialization and wiring, following Clean
Architecture principles and improving maintainability.

- internal/app/di.go: Complete DI container implementation with lazy
  initialization, singleton pattern, and clean resource management
- internal/app/di_test.go: Comprehensive test suite with 6 test cases
- internal/app/README.md: Detailed documentation with examples and guides
- REFACTORING_SUMMARY.md: Complete summary of refactoring changes

- cmd/app/main.go: Simplified from 236 to 182 lines (-23%)
  - Removed manual dependency wiring from runServer() and runWorker()
  - Removed setupLogger() function (moved to container)
  - Replaced closeDB() with closeContainer()
  - All commands now use container pattern
- README.md: Updated project documentation
  - Added DI container to features list
  - Updated project structure to include internal/app/
  - Added comprehensive DI container documentation section
  - Enhanced "Adding New Domains" guide with DI registration steps

- **Lazy Initialization**: Components created only on first access
- **Singleton Pattern**: Each component initialized once and reused
- **Thread-Safe**: Using sync.Once for concurrent access safety
- **Error Handling**: Comprehensive error propagation and storage
- **Resource Cleanup**: Unified Shutdown() method for all resources
- **Testability**: Easily testable and mockable for integration tests

1. Centralized dependency management - all wiring in one place
2. Simplified main.go - reduced complexity by 23%
3. Eliminated duplicate initialization code across commands
4. Improved testability with mockable container
5. Better scalability - easy to add new domains
6. Clean resource management with unified shutdown
7. No external DI framework dependencies
@allisson allisson merged commit b8e1b49 into main Jan 24, 2026
1 check passed
@allisson allisson deleted the usecase-interface branch January 24, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant