Dagger's Assisted Injection: Creating Objects with Runtime Data
Assisted Injection lets Dagger provide some dependencies while you supply the rest at runtime. It's for objects that need both graph-provided services and user-supplied data, like a specific ID. The footgun: you can't inject the object, only its factory.
Assisted Injection is a factory pattern where Dagger provides some constructor parameters and you provide the others at creation. It's for objects needing both graph-managed dependencies and runtime data, like a user ID from navigation arguments. Dagger can't know this data ahead of time, so you 'assist' it. The main footgun is trying to inject the class directly; you must inject its `@AssistedFactory` and call `create()`. These objects also cannot be scoped.
Read the original → dagger.dev
- #android
- #kotlin
- #dependency injection
- #dagger
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.