Performance: Constructor injection
MEDIUM IMPACT
Constructor injection affects the initialization speed of services and components during app startup, impacting the time to first meaningful paint.
import { Injectable } from '@nestjs/common'; import { SomeDependency } from './some-dependency'; @Injectable() export class MyService { constructor(private readonly dependency: SomeDependency) {} }
import { Injectable, Injector } from '@nestjs/common'; import { SomeDependency } from './some-dependency'; @Injectable() export class MyService { private dependency: SomeDependency; constructor(private injector: Injector) {} async init() { this.dependency = this.injector.get(SomeDependency); } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual Injector.get() calls | 0 (no DOM impact) | 0 | Blocks script execution delaying paint | [X] Bad |
| Constructor injection | 0 (no DOM impact) | 0 | Non-blocking synchronous init, faster paint | [OK] Good |