Service Locator (ARCH8198)
Ce contenu n’est pas encore disponible dans votre langue.
Key kotlin.quality.service-locator · Severity warning · Category quality
Flags services resolved at runtime from a container (applicationContext.getBean, Koin get() / inject() inside functions) instead of constructor injection.
Incorrect
Section titled “Incorrect”class Svc { fun run() { val repo = ctx.getBean(Repo::class.java) } }Correct
Section titled “Correct”class Svc(private val repo: Repo) { fun run() = repo.load() }Inject the dependency through the constructor.