https://kotlinlang.org logo
#compose
Title
# compose
u

ursus

11/20/2021, 9:25 PM
Has someone integrated Dagger in such a way where dagger provides Screen composables? if so, how, ifi ts just
() -> @Composable Unit
lamdas? Qualifieres everywhere? Or maybe some typesafe object based Screen? is that a bad idea? (since it doesnt really compose if needed, same way fragments sort of did)
b

Bradleycorn

11/21/2021, 2:41 PM
I’m not sure how this would work, or why you would need it? The purpose of dagger (or any DI framework) is to create and inject instances of objects in a class, rather than the class having to create them itself. It exists to solve a problem where a class A that needs to use an instance of another class B needs to know the details about how to create an instance of B (which could mean creating instances of several other objects as well). But composables are not objects or classes, but just simple functions. There’s no instance to create, and thus there’s no problem to solve.
u

ursus

11/21/2021, 3:03 PM
Well Im mostly talking about instantiation of the viewmodels passed in, someone needs to construct them
i

Ian Lake

11/21/2021, 4:09 PM
Hilt has integrations with Compose to provide ViewModels, including providing them at the screen by screen level (via integration with Navigation Compose): https://developer.android.com/jetpack/compose/libraries#hilt
2 Views