I know decompose comes with dependency injection o...
# decompose
a
I know decompose comes with dependency injection out of the box, but as my projects were growing I switched over to kotlin-inject and kotlin-inject-anvil and was getting tired of writing a bunch of boiler plate code for the binding assisted factory interfaces similar to dagger. Since decompose heavily relies on assisted injection of the
ComponentContext
, I wrote a library that extends kotlin-inject-anvil to help bind and generate the assisted factory interface glue code to bind it in the kotlin-inject dependency graph that I thought others who use the library might be interested in. https://plusmobileapps.com/blog/2025/04/04/kotlin-inject-anvil-extensions/
🙌 1
👍 1
a
Nice, thanks! Btw, your library looks similar to this one for Dagger+Anvil: https://github.com/IlyaGulya/anvil-utils
a
Very similar to that library, but adapted to kotlin-inject to be used in KMP projects!
👍 1
c
I am not sure if this is related to this topic, but I found that putting the factory of Decompose components into the DI container is more suitable than putting the Decompose components into the DI container, because it is quite hard to map the life cycle of Decompose component to lifecycle in any DI framework/library. Hence I think it is better to inject factories instead of the components, as factories can just be application scope singletons https://medium.com/@yeldar.nurpeissov/master-kotlin-multiplatform-navigation-with-decompose-add-di-with-kodein-and-koin-405462b2691b
a
Yeah, the so called Assisted Inject pattern works well with Decompose and DI frameworks like Dagger/kotlin-inject etc.