dead.fish
04/02/2025, 3:43 PMactivityRetainedScope()
. This is my setup:
// MyActivity.kt
class MyActivity : AppCompatActivity(), AndroidScopeComponent {
override val scope: Scope by activityRetainedScope()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
// I also tried CompositionLocalProvider(LocalKoinScope provides scope) { ... }
KoinAndroidContext {
AppNavHost()
}
}
}
}
// AppNavHost.kt
fun AppNavHost(
appBarActionsProvider: AppBarActionProvider = koinInject<AppBarActionProvider>(),
...
) { ... }
// MyModule.kt
fun myModule(): KoinModule =
module {
scope<ComponentActivity> {
scopedOf(::AppBarActionHandler) binds arrayOf(AppBarActionProvider::class, AppBarActionObserver::class)
}
...
}
However, my injection of AppBarActionProvider
is not found. I'm unsure what the Scope
generic argument of scope()
must be, the base class or something else?dead.fish
04/02/2025, 4:00 PMLocalKoinScope
with scope
and using scoped<MyActivity> { ... }
, now however I am not able to inject AppBarActionObserver
in another injectee injected itself via koinViewModel
. I guess the scope koinViewModel
creates only knows of the root scope, but not my custom activityRetainedScope
...dead.fish
04/03/2025, 9:13 AMdead.fish
04/03/2025, 3:42 PMviewModelOf(::MyViewModel)
declaration inside my scope<MyActivity> { }
block so that things provided inside that scope become accessible. Only downside I see here is that I always have to reference specific types here, i.e. MyActivity
, to scope things, as activityRetainedScope
does not allow me to specify another, more generic scope specifier, so things that should be scoped underneath Activities and that should also be shared between different activities do not work.arnaud.giuliani
05/07/2025, 2:15 PM