Refactor dependency injection and code style improvements - #1475
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors dependency injection across application/UI modules by moving repository/use-case wiring into the app DI container and converting several module-scope singletons into injected factories, aligning the codebase with the documented DI architecture (Fixes #515).
Changes:
- Centralizes wiring for multiple feature modules in
src/di/container.tsxand removes the legacy globalsrc/di/useCases.ts. - Converts several application modules (recent-food, weight chart settings, cached search, measure, macro profile, recipe item use cases) to accept explicit injected dependencies instead of constructing infra defaults internally.
- Updates UI/components and tests to consume container-owned instances via
useContainer().
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/shared/utils/tests/convertApi2Food.test.ts | Updates import to new convertApi2Food location. |
| src/sections/weight/components/WeightEvolution.tsx | Switches chart settings access to container-provided weightChartSettings. |
| src/sections/search/components/TemplateSearchModal.tsx | Uses container-provided recentFoodUseCases instead of direct imports. |
| src/sections/item/components/ItemView/ItemViewHeader/ItemViewName.tsx | Moves recipe item use-cases access to useContainer(). |
| src/sections/item/components/ItemView/ItemEdit/ItemQuantityControls.tsx | Moves recipe item use-cases access to useContainer(). |
| src/sections/item/components/ItemView/ItemEdit/ItemEditModal.tsx | Wires recipeItemUseCases from container. |
| src/sections/ean/components/EANSearch.tsx | Removes module-scope CRUD wiring; uses container foodCrud. |
| src/sections/common/components/buttons/RemoveFromRecentButton.tsx | Uses container recentFoodUseCases for deletion. |
| src/modules/weight/application/weight/usecases/weightUseCases.ts | Requires injected repositories (cache + weight repo) rather than building defaults. |
| src/modules/weight/application/chart/weightChartSettings.ts | Replaces global signals with a factory (createWeightChartSettings) using an injected repository. |
| src/modules/template-search/application/usecases/templateSearchState.ts | Requires injected recentFoodCrud, foodCrud, and recipeCrud. |
| src/modules/search/application/usecases/cachedSearchCrud.ts | Requires injected repository instead of constructing a default one. |
| src/modules/recent-food/application/usecases/recentFoodCrud.ts | Makes repository injection mandatory (still supports showPromise override). |
| src/modules/measure/application/usecases/measureState.ts | Requires injected fetcher for body measures; keeps realtime init injectable. |
| src/modules/measure/application/usecases/measureCrud.ts | Makes measure repository injection mandatory. |
| src/modules/diet/recent-food/ui/tests/RemoveFromRecentButton.test.tsx | Updates test logic to reflect container-backed flow. |
| src/modules/diet/recent-food/application/usecases/touchRecentFoodForItem.ts | Converts to factory with injected touchRecentFood. |
| src/modules/diet/recent-food/application/usecases/touchRecentFood.ts | Converts to factory with injected auth + CRUD collaborators. |
| src/modules/diet/recent-food/application/usecases/tests/touchRecentFoodForItem.test.ts | Updates test to use the new factory. |
| src/modules/diet/recent-food/application/usecases/tests/touchRecentFood.test.ts | Updates test to use the new factory. |
| src/modules/diet/recent-food/application/usecases/recentFoodUseCases.ts | Converts recent-food use cases to a factory and composes injected collaborators. |
| src/modules/diet/recent-food/application/usecases/deps.ts | Removes centralized module-scope wiring for recent-food service. |
| src/modules/diet/macro-profile/application/usecases/macroProfileUseCases.ts | Makes CRUD service injection mandatory. |
| src/modules/diet/macro-profile/application/service/macroProfileCrudService.ts | Makes repository injection mandatory. |
| src/modules/diet/item/application/tests/recipeItemUseCases.test.ts | Updates test to use createRecipeItemUseCases factory. |
| src/modules/diet/item/application/recipeItemUseCases.ts | Removes module-scope singleton export; keeps factory + exported type. |
| src/modules/diet/food/infrastructure/api/application/convertApi2Food.ts | Minor style tweak; now the canonical conversion location. |
| src/modules/diet/food/infrastructure/api/application/apiFood.ts | Makes DI explicit (repository + cached-search CRUD required); updates imports. |
| src/modules/diet/food/application/usecases/foodCrud.ts | Requires injected cachedSearchCrud and repository instance. |
| src/modules/diet/day-diet/application/usecases/dayUseCases.ts | Makes dayRepository mandatory (injected by container). |
| src/di/useCases.ts | Removes legacy global use-cases container. |
| src/di/container.tsx | Centralizes construction and exposure of repositories/use-cases/settings via DI container. |
| docs/ARCHITECTURE_GUIDE.md | Updates DI guidelines to match the refactor (container/test-only concrete wiring, UI uses useContainer()). |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Centralize dependency injection for better maintainability and clarity. Simplify imports and enhance code style for improved readability.
Fixes #515