Thread
#compose
    henrikhorbovyi

    henrikhorbovyi

    2 years ago
    Koin + Compose What do you think about this approach?
    Injectable {
        val myDependency: MyDependecy by inject() 
        HomeScreen(myDependency)     
    }
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    What does
    Injectable
    do?
    henrikhorbovyi

    henrikhorbovyi

    2 years ago
    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
    pavi2410

    pavi2410

    2 years ago
    You can use
    get()
    inside a function
    henrikhorbovyi

    henrikhorbovyi

    2 years ago
    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()
    henrikhorbovyi

    henrikhorbovyi

    2 years ago
    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
    @Composable
    fun MyScreen() {
       // call your KoinComponent.get() here
    }
    And event if I could I would use
    inject
    extension which is lazy
    pavi2410

    pavi2410

    2 years ago
    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?
    henrikhorbovyi

    henrikhorbovyi

    2 years ago
    Oh! I got your point. You are just asking me to do
    Injectable {
        val repository = get<MyRepository>()
        HomeScreen(repository)
    }
    instead of:
    Injectable {
        val repository by inject<MyRepository>()
        HomeScreen(repository)
    }
    is it?
    pavi2410

    pavi2410

    2 years ago
    Yeah
    I also got your point 😁
    henrikhorbovyi

    henrikhorbovyi

    2 years ago
    😄