https://kotlinlang.org logo
Title
d

dave08

01/17/2022, 4:53 PM
@evant Do you have any plans to add something like Dagger's
fun inject(someActivity: SomeActivity)
...? It's SO MUCH nicer than having to do the trick in the Android docs on kotlin-inject's Github repo...
e

evant

01/17/2022, 4:58 PM
No plans to add field or function injection. It can leave objects in a partially constructed state which can cause runtime issues if you aren't careful. Pulling your logic out of your activity also makes it easier to test.
d

dave08

01/17/2022, 4:59 PM
What difference is it from:
class MyActivity : Activity() {
    private lateinit var myScreen: MyScreen

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate()
        myScreen = ActivityComponent::class.create(ApplicationComponent.getInstance(this)).myScreen
e

evant

01/17/2022, 5:02 PM
All the important bits are in MyScreen which you can easily construct and unit test
d

dave08

01/17/2022, 5:03 PM
I was really considering to use kotlin-inject instead of Hilt for a bigger module in our app... but I have a bunch of workmanagers that need to be injected with multiple deps, and that could get a bit messy. That separation I do already in what I'm injecting... but I need to manually give all those to each workmanager... which is a lot of boilerplate...
e

evant

01/17/2022, 5:07 PM
https://developer.android.com/reference/androidx/work/WorkerFactory ? Could do the same thing that's suggested for fragments
Working on a generator for the fragment boilerplate actually, could do the same thing for workers https://github.com/evant/kotlin-inject-android
p

Paul Woitaschek

01/17/2022, 6:12 PM
@evant it says kotlin-injeft
e

evant

01/17/2022, 6:24 PM
Lol
Fixed