i would like to just write ```val router by inject...
# koin
a
i would like to just write
Copy code
val router by inject<RouterViewModel>()
but its a compilation error
🧵 1
p
it's a view model you can use
Copy code
val router: RouterViewModel by viewModel()
a
its not really a viewmodel :p
p
but you need to provide like viewmodel
a
im not on android
p
ohhh ok sorry 😞
but where are you trying to inject ?
a
Inside a Composable function
sorry i accidentally split up my question into 2 messages
(i am using compose multiplatform for desktop jvm)
p
oh wow nice
but the class where you trying to inject that is extending KoinComponent ?
a
the Composable isnt inside a class
its a global function
p
for composable there is other dependency
but am not sure if this only works for view models
since the injection looks like this
Copy code
@Composable
fun ViewModelInject(userName : String, viewModel: UserViewModel = koinViewModel()){
    Text(text = viewModel.sayHello(userName), modifier = Modifier.padding(8.dp))
}
a
theres another example
Copy code
@Composable
fun FactoryInject(userName : String, presenter: UserStateHolder = get()){
    Text(text = presenter.sayHello(userName), modifier = Modifier.padding(8.dp))
}
but i think that if i tried to use just get, it would still ask me to provide a class parameter
p
so just to undesrtand your RouterViewModel need attributes from the composable ?
a
let me share a bigger snippet
im early in the project so this is the majority of my code :P
Copy code
@Composable
@Preview
fun App() {
     val router by inject<RouterViewModel>(RouterViewModel::class.java)

     val routerState: Backstack<AppRoutes> by router.observeStates().collectAsState()

     routerState.renderCurrentDestination(
          route = {
               appRoute ->
               when(appRoute) {
                    AppRoutes.Home -> {
                         HomeScreen()
                    }
               }
          },
          notFound = {}
     )
}

fun main() = application {
    startKoin {
        modules(appModule)
    }
    Window(onCloseRequest = ::exitApplication) {
        App()
    }
}
so you see, theres not too much going on. and, to note, this code works
the inject im using isnt from \a class that implements KoinContainer
but the KoinJavaContainer object
p
maybe is the wrong import ?
not sure sisnce I never used koin in KMM