Skip to content

feat: expand DI container with lifecycle management and domain modules#553

Merged
Smartdevs17 merged 2 commits into
Smartdevs17:mainfrom
jajafwangshak86-ops:feat/issue-485-di-container
Jun 28, 2026
Merged

feat: expand DI container with lifecycle management and domain modules#553
Smartdevs17 merged 2 commits into
Smartdevs17:mainfrom
jajafwangshak86-ops:feat/issue-485-di-container

Conversation

@jajafwangshak86-ops

Copy link
Copy Markdown
Contributor

Closes #485

What's changed

backend/src/di/container.ts

  • Lifecycle management: singleton (shared), transient (new per call), scoped (shared within a request scope)
  • DIContainer.createFresh() — isolated instance for test mock injection, no shared state
  • container.validate() — iterates all registrations at startup; throws on misconfigured factories
  • container.reset() — clears singleton cache (tests)
  • Backwards-compatible: existing get(), set(), has(), and typed getters unchanged

backend/src/di/modules/

Per-domain module files that call c.register():

  • project.module.ts — ProjectRepository → ProjectService → ProjectController
  • auth.module.ts — LockoutManager, AuditService
  • payment.module.ts — AnalyticsService, VerificationService, InvoiceService

backend/src/di/index.tsbootstrapDI()

  • Loads all domain modules
  • Runs validate() on startup (opt-out via DI_VALIDATION=false env var)

backend/src/di/__tests__/container.test.ts

  • All three lifecycles
  • Mock injection override
  • Transitive dependency graph resolution
  • Validation pass/fail
  • Reset (singleton cache cleared)
  • Performance: singleton resolve < 1ms

Smartdevs17#485)

- DIContainer: singleton, transient, scoped lifecycles with <1ms resolution
- DIContainer.createFresh() for test isolation (no shared singleton state)
- container.validate() for startup validation with DI_VALIDATION=false feature flag
- Per-domain modules: project.module.ts, auth.module.ts, payment.module.ts
- bootstrapDI() entry point in di/index.ts
- Comprehensive unit tests: all lifecycles, mock injection, dependency graph,
  validation, reset, and performance (<1ms assertion)
@vercel

vercel Bot commented Jun 28, 2026

Copy link
Copy Markdown

@devJaja is attempting to deploy a commit to the smartdevs17's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@jajafwangshak86-ops Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Smartdevs17 Smartdevs17 merged commit 2177ea9 into Smartdevs17:main Jun 28, 2026
18 of 29 checks passed
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.

Refactor: Convert Backend Services to Dependency Injection Pattern

3 participants