raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.23k stars 134 forks source link

dependenciesContainerBuilder / dependency() related question #685

Closed miduch closed 1 month ago

miduch commented 2 months ago

Hi, Is it possible to achieve following

    val somethingA: Something<A>()
    val somethingB: Something<B>()

    DestinationsNavHost(
        dependenciesContainerBuilder = {
            dependency(somethingA)
            dependency(somethingB)
        }
    )

get dependency in screen side

@Composable
fun MyScreen(
    somethingA: Something<A>,
    somethingB: Something<B>,
) {
}   

dependency map in DestinationDependenciesContainerImpl has only one entry in my case and value is somethingB. Other somethingA is no where to be found

raamcosta commented 1 month ago

Hey @miduch 👋

Unfortunately not like that. I don't want to turn this feature into a full fledged DI framework 😄 Personally, I would wrap these in some other classes with different types and use those instead, or I would call the composables manually (as described here: https://composedestinations.rafaelcosta.xyz/v2/arguments/nav-host-parameters#manually-call-your-screen-composable).

miduch commented 1 month ago

Hey @miduch 👋

Unfortunately not like that. I don't want to turn this feature into a full fledged DI framework 😄 Personally, I would wrap these in some other classes with different types and use those instead, or I would call the composables manually (as described here: https://composedestinations.rafaelcosta.xyz/v2/arguments/nav-host-parameters#manually-call-your-screen-composable).

that dependency wasn't 100% UI related and was able to move to hilt where it belonged