fix: enable DI for FeatureOptInService#124
Conversation
Review Summary by QodoEnable dependency injection for FeatureOptInService and FeaturesRepository
WalkthroughsDescription• Enable dependency injection for FeatureOptInService and FeaturesRepository • Create DI containers and modules for feature-opt-in and flags services • Extract ResolvedFeatureState type into IFeatureOptInService interface • Update imports across codebase to use DI containers instead of direct instantiation Diagramflowchart LR
A["Features Module<br/>Features.ts"] -->|"refactored to"| B["FeaturesRepository Module<br/>FeaturesRepository.ts"]
C["FeatureOptInService<br/>Direct instantiation"] -->|"refactored to"| D["FeatureOptInService Module<br/>FeatureOptInService.ts"]
B -->|"dependency"| D
D -->|"exposed via"| E["DI Container<br/>FeatureOptInService.ts"]
B -->|"exposed via"| F["DI Container<br/>FeaturesRepository.ts"]
G["IFeatureOptInService<br/>Interface"] -->|"implemented by"| H["FeatureOptInService<br/>Class"]
I["TRPC Router<br/>_router.ts"] -->|"uses"| E
J["Integration Tests<br/>integration-test.ts"] -->|"uses"| E
J -->|"uses"| F
File Changes1. packages/features/di/modules/FeaturesRepository.ts
|
Code Review by Qodo
1. IFeatureOptInService formatting violations
|
| orgAutoOptIn: boolean; | ||
| teamAutoOptIns: boolean[]; | ||
| userAutoOptIn: boolean; | ||
| }; | ||
|
|
||
| export interface IFeatureOptInService { | ||
| resolveFeatureStatesAcrossTeams(input: { | ||
| userId: number; | ||
| orgId: number | null; | ||
| teamIds: number[]; | ||
| featureIds: FeatureId[]; | ||
| }): Promise<Record<string, ResolvedFeatureState>>; | ||
| listFeaturesForUser(input: { userId: number; orgId: number | null; teamIds: number[] }): Promise< | ||
| ResolvedFeatureState[] | ||
| >; | ||
| listFeaturesForTeam( | ||
| input: { teamId: number } | ||
| ): Promise<{ featureId: FeatureId; globalEnabled: boolean; teamState: FeatureState }[]>; |
There was a problem hiding this comment.
1. ifeatureoptinservice formatting violations 📘 Rule violation ✓ Correctness
The newly added interface file contains trailing whitespace and several overly long lines that do not conform to the repository’s Biome formatting rules. This reduces consistency and can cause formatter/linter failures in CI.
Agent Prompt
## Issue description
The new `IFeatureOptInService.ts` file contains Biome formatting violations (trailing whitespace and long lines) that may fail formatting checks and reduces consistency.
## Issue Context
Compliance requires TypeScript files to adhere to the repo’s Biome formatting rules (line width, whitespace, etc.).
## Fix Focus Areas
- packages/features/feature-opt-in/services/IFeatureOptInService.ts[11-28]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| export const moduleLoader: ModuleLoader = { | ||
| token: moduleToken, | ||
| loadModule, | ||
| }; |
There was a problem hiding this comment.
2. Wrong di token exported 🐞 Bug ✓ Correctness
packages/features/di/modules/FeaturesRepository.ts exports moduleLoader.token as the module token instead of the binding token, so bindModuleToClassOnToken injects an unbound token and container.get() is called with a token that was never bound. This causes runtime DI resolution failures for services that depend on FeaturesRepository (e.g., RegularBookingService, BookingAuditTaskConsumer, FeatureOptInService) and for getFeaturesRepository().
Agent Prompt
### Issue description
`packages/features/di/modules/FeaturesRepository.ts` binds `FeaturesRepository` on `FLAGS_DI_TOKENS.FEATURES_REPOSITORY` but exports `moduleLoader.token` as `FLAGS_DI_TOKENS.FEATURES_REPOSITORY_MODULE`. The DI helper `bindModuleToClassOnToken` uses `dep.token` for constructor injection, and containers use `moduleLoader.token` for `container.get()`, so consumers try to resolve an unbound token at runtime.
### Issue Context
Other modules’ loaders export the *binding* token (e.g., MembershipRepository). `moduleToken` is only meant for `container.load(moduleToken, module)`.
### Fix Focus Areas
- packages/features/di/modules/FeaturesRepository.ts[7-22]
- packages/features/di/containers/FeaturesRepository.ts[4-8]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Benchmark PR from agentic-review-benchmarks#13