Service Locator Injection (ARCH3198)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
Key typescript.quality.service-locator · Severity warning · Category quality
Injecting the DI container or provider itself and resolving services at runtime hides dependencies and harms testability. Dependencies should be injected explicitly through the constructor.
Incorrect
Section titled “Incorrect”class OrderService { constructor(private container: Container) {}
process() { const repo = this.container.resolve<OrderRepo>("OrderRepo"); repo.save(); }}Correct
Section titled “Correct”class OrderService { constructor(private repo: OrderRepo) {}
process() { this.repo.save(); }}Inject the specific services you need directly into the constructor instead of the container.