Which approach is preferrable when injecting simpl...
# koin
z
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
here is more relative to readability and depends if you are using some lazy also
👍🏽 1
I would go for
get<AuthService>()
directly
👍🏽 1
👍 1
p
Currently am trying to avoid custom initializers in the modules. So in my case I would go with passing the authService to SomeService and in there when needed fetch User Id in the init method. Why? Because then you can use directly singleOf(::SomeService)
👍🏽 1