تخطَّ إلى المحتوى

Service Locator Injection (ARCH3198)

هذا المحتوى غير متوفر بلغتك بعد.

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.

class OrderService {
constructor(private container: Container) {}
process() {
const repo = this.container.resolve<OrderRepo>("OrderRepo");
repo.save();
}
}
class OrderService {
constructor(private repo: OrderRepo) {}
process() {
this.repo.save();
}
}

Inject the specific services you need directly into the constructor instead of the container.