fix: ensure database and HTTP server providers execute on startup

- Add fx.Invoke in main.go to force database and HTTP server creation
- This ensures all providers execute and their lifecycle hooks are registered
- Clean up debug logging statements
- Database migrations and HTTP server now start correctly on application startup

Fixes issue where database migrations and HTTP server were not starting
because FX providers were not being executed (lazy evaluation).
This commit is contained in:
2025-11-05 20:32:20 +01:00
parent 84673c33b1
commit 0e3bfb4e44
3 changed files with 31 additions and 4 deletions

View File

@@ -7,15 +7,24 @@ import (
"os"
"git.dcentral.systems/toolz/goplt/internal/di"
"git.dcentral.systems/toolz/goplt/internal/infra/database"
"git.dcentral.systems/toolz/goplt/internal/server"
"git.dcentral.systems/toolz/goplt/pkg/logger"
"go.uber.org/fx"
)
func main() {
// Create DI container with lifecycle hooks
// We need to invoke the HTTP server to ensure all providers execute
container := di.NewContainer(
// Invoke lifecycle hooks
fx.Invoke(di.RegisterLifecycleHooks),
// Force HTTP server to be created (which triggers all dependencies)
// This ensures database, health, metrics, etc. are all created
fx.Invoke(func(srv *server.Server, dbClient *database.Client) {
// Both server and database are created, hooks are registered
// This ensures all providers execute
}),
)
// Create root context