tercul-backend/internal/app/app.go
google-labs-jules[bot] a68db7b694 refactor(app): move composition root to main.go
Refactored the application's dependency injection and server setup to improve modularity and adhere to the Dependency Inversion Principle.

- Moved the instantiation of all application services from `internal/app/app.go` to the composition root in `cmd/api/main.go`.
- The `app.NewApplication` function now accepts pre-built service interfaces, making the `app` package a simple container.
- Updated `internal/testutil/integration_test_utils.go` to reflect the new DI pattern, ensuring tests align with the refactored structure.
- Corrected build errors that arose from the refactoring, including import conflicts and incorrect function calls.
- Updated `TASKS.md` to mark the 'Refactor Dependency Injection' task as complete.
2025-10-07 14:05:19 +00:00

83 lines
2.3 KiB
Go

package app
import (
"tercul/internal/app/analytics"
"tercul/internal/app/auth"
"tercul/internal/app/author"
"tercul/internal/app/authz"
"tercul/internal/app/book"
"tercul/internal/app/bookmark"
"tercul/internal/app/category"
"tercul/internal/app/collection"
"tercul/internal/app/comment"
"tercul/internal/app/contribution"
"tercul/internal/app/like"
"tercul/internal/app/localization"
appsearch "tercul/internal/app/search"
"tercul/internal/app/tag"
"tercul/internal/app/translation"
"tercul/internal/app/user"
"tercul/internal/app/work"
)
// Application is a container for all the application-layer services.
type Application struct {
Author *author.Service
Book *book.Service
Bookmark *bookmark.Service
Category *category.Service
Collection *collection.Service
Comment *comment.Service
Contribution *contribution.Service
Like *like.Service
Tag *tag.Service
Translation *translation.Service
User *user.Service
Localization *localization.Service
Auth *auth.Service
Authz *authz.Service
Work *work.Service
Search appsearch.Service
Analytics analytics.Service
}
// NewApplication creates a new Application container from pre-built services.
func NewApplication(
authorSvc *author.Service,
bookSvc *book.Service,
bookmarkSvc *bookmark.Service,
categorySvc *category.Service,
collectionSvc *collection.Service,
commentSvc *comment.Service,
contributionSvc *contribution.Service,
likeSvc *like.Service,
tagSvc *tag.Service,
translationSvc *translation.Service,
userSvc *user.Service,
localizationSvc *localization.Service,
authSvc *auth.Service,
authzSvc *authz.Service,
workSvc *work.Service,
searchSvc appsearch.Service,
analyticsSvc analytics.Service,
) *Application {
return &Application{
Author: authorSvc,
Book: bookSvc,
Bookmark: bookmarkSvc,
Category: categorySvc,
Collection: collectionSvc,
Comment: commentSvc,
Contribution: contributionSvc,
Like: likeSvc,
Tag: tagSvc,
Translation: translationSvc,
User: userSvc,
Localization: localizationSvc,
Auth: authSvc,
Authz: authzSvc,
Work: workSvc,
Search: searchSvc,
Analytics: analyticsSvc,
}
}