Field Injection (ARCH8200)
Key kotlin.quality.field-injection · Severity warning · Category quality
Flags @Autowired / @Inject on properties (lateinit var) instead of constructor parameters. Android entry points - Application, Activity, Fragment, Service, Worker - are excepted: the framework constructs them and constructor injection is impossible.
Incorrect
Section titled “Incorrect”@Autowired lateinit var repo: OrderRepositoryCorrect
Section titled “Correct”class OrderService(private val repo: OrderRepository)Inject through the constructor.