Koin + Compose What do you think about this approa...
# compose
h
Koin + Compose What do you think about this approach?
Copy code
Injectable {
    val myDependency: MyDependecy by inject() 
    HomeScreen(myDependency)     
}
z
What does
Injectable
do?
h
Just work around to allow the use o
KoinComponent.inject()
Because I can't use
inject()
inside a function, so
Injectable
gives me an
InjectableComponent
in its scope which is a KoinComponent
p
You can use
get()
inside a function
h
But
get
just return a KoinApplication
Actually get has no <T>
But with the
Injectable
composable it works, cause I can call the extension
fun <T> KoinComponent.get()
h
exactly what I'm using, but you can't call
KoinComponent.get
from inside a scope which is not a KoinComponent
Try it: 1 - Create a file 2 - Create the following composable
Copy code
@Composable
fun MyScreen() {
   // call your KoinComponent.get() here
}
And event if I could I would use
inject
extension which is lazy
p
I am not sure why you can't call
get()
when you can acesss
inject()
as both are extension functions of
KoinComponent
.
And, if a lazy property is called immediately, how is it different than calling
get()
directly?
h
Oh! I got your point. You are just asking me to do
Copy code
Injectable {
    val repository = get<MyRepository>()
    HomeScreen(repository)
}
instead of:
Copy code
Injectable {
    val repository by inject<MyRepository>()
    HomeScreen(repository)
}
is it?
p
Yeah
I also got your point 😁
h
😄