https://kotlinlang.org logo
#koin
Title
# koin
z

Zoltan Demant

10/30/2023, 9:47 AM
Which approach is preferrable when injecting simple fields into a class? In this case, user is
fun interface User { fun userId(): String? }
• by inject in
single {}
get()
in the actual function call
Copy code
single {
    val authService by inject<AuthService>()

    SomeService(
        context = get(),
        user = {
            // get<AuthService>().user()?.id

            val user = authService.user()
            user?.id
        },
    )
}
👀 1
a

arnaud.giuliani

10/30/2023, 3:41 PM
here is more relative to readability and depends if you are using some lazy also
👍🏽 1
I would go for
get<AuthService>()
directly
👍🏽 1
2 Views