1import { Global, Module } from "@nestjs/common"; 2import { PrismaService } from "./prisma.service.js"; 3import { RedisService } from "./redis.service.js"; 4import { EventBus } from "./event-bus.js"; 5import { AuditService } from "./audit.service.js"; 6import { EmailService } from "./email.service.js"; 7import { CacheService } from "./cache.js"; 8import { PermissionCacheBridge } from "./permission-cache-bridge.js"; 9 10/** 11 * Global core services (TASK-0100 S0 — repo-wide DI fix). 12 * 13 * **Why this module exists.** Nest resolves plain `private readonly` ctor 14 * injection against the *module's own scope*: a provider is injectable only if 15 * it is declared (or imported/exported) in the same module, or provided by a 16 * `@Global()` module. The five shared services used to be declared in the 17 * root `AppModule` — which NO feature module imports — so: 18 * 19 * - under the **tsc-compiled** runtime (metadata emitted), boot threw 20 * `Nest can't resolve dependencies of ...` for every feature service; 21 * - under **tsx / vitest** (esbuild: `design:paramtypes` is NEVER emitted — 22 * esbuild has no decorator-metadata support), boot "succeeded" and every 23 * plain-injected dependency resolved to `undefined`, surfacing as 500s at 24 * request time (e.g. login: `this.auth` undefined). 25 * 26 * **Fix (two halves, both required):** 27 * 1. this `@Global()` module — makes the five services visible to every 28 * feature module without per-module imports (verified empirically: the 29 * plain-injection shape fails to boot without a global module, boots with 30 * one, under both tsc and tsx); 31 * 2. explicit `@Inject(Token)` on every DI ctor param across the app — 32 * explicit tokens resolve under every transform (tsx, vitest, tsc) 33 * regardless of emitted metadata, so the app boots identically in dev, 34 * test and build runtimes. 35 */ 36@Global() 37@Module({ 38 providers: [PrismaService, RedisService, EventBus, AuditService, EmailService, CacheService, PermissionCacheBridge], 39 exports: [PrismaService, RedisService, EventBus, AuditService, EmailService, CacheService] 40}) 41export class CoreModule {} 42