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
arnaud.giuliani
10/30/2023, 3:42 PM
I would go for
get<AuthService>()
directly
šš½ 1
š 1
p
Pedro Alberto
12/23/2023, 9:12 PM
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)