Hi, how can we inject dependencies in Composable i...
# multiplatform
a
Hi, how can we inject dependencies in Composable in compose multiplatform?
🧵 1
🤔 1
d
There are two major ways to get objects into a Composable, including objects ones might classify as 'dependencies': Function parameter, Composition Local.
a
Can you share any sample?
m
I guess you're looking for koin or kotlin-inject?
a
koin
@mbonnin
d
@Ahmad Hassan Martin already linked you to the Koin site which, of course, has comprehensive documentation including for Compose use cases. I'm not sure what more you're expecting by tagging him?
At some point you're going to have to do the work and figure it out.
a
Well, it’s for Jetpack Compose. I want to use it in JetBrains Compose.
d
Well what have you tried? Have you tried applying the Jetpack examples to Multiplatform? Or do you just want to be spoonfed the answer?
AFAIK there isn't really any common standard around DI in Compose Multiplatform at the moment, it's too small.
...for any framework.
a
No, I don’t want to be spoonfed. I already check docs, internet but have not found any material
d
I'm doing Compose Multiplatform projects but not using a DI framework, instead preferring to write my own convention/patterns using 'module' `object`s
m
I think recently Koin team added
koin-compose
module: https://github.com/InsertKoinIO/koin/blob/main/compose/koin-compose/build.gradle but I am not sure how it works since i didn’t played with it at all
you should manually try using it and if doens’t work or has bugs perhaps you should create issue in their GitHub page so you can contribute them
d
Yeah worth having a look at the
koin-compose
module it's possible they added Multiplatform support but didn't explicitly call it out (since they're MP anyway).
With tech this new; things may not be fully documented or advertised (especially when it comes to combinations of them).
An element of 'try and see if it works' often produces results.
m
+1 to everything that has been said. At this point, I would try Koin with compose multiplatform and ask in #koin if it doesn't work (but maybe it just works 🙂 )
d
🔍 https://insert-koin.io/docs/reference/koin-compose/multiplatform ...must have missed this one @Ahmad Hassan 😅
m
Nice!
d
...and go team Koin! K K
m
a
Thanks! @darkmoon_uk @Mustafa Ozhan Well, I already go through this and tried to add dependency but faced this issue:
Copy code
A problem occurred configuring project ':shared'.
> Could not resolve all dependencies for configuration ':shared:iosArm64CompileKlibraries'.
   > Could not resolve io.insert-koin:koin-compose:1.0.0.
     Required by:
         project :shared
      > No matching variant of io.insert-koin:koin-compose:1.0.0 was found. The consumer was configured to find a library for use during 'kotlin-api', preferably optimized for non-jvm, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native', attribute 'org.jetbrains.kotlin.native.target' with value 'ios_arm64' but:
          - Variant 'jsApiElements-published' capability io.insert-koin:koin-compose:1.0.0 declares a library for use during 'kotlin-api':
              - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
          - Variant 'jsRuntimeElements-published' capability io.insert-koin:koin-compose:1.0.0 declares a library:
              - Incompatible because this component declares a component for use during 'kotlin-runtime', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'js' and the consumer needed a component for use during 'kotlin-api', as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'native'
              - Other compatible attributes:
                  - Doesn't say anything about its target Java environment (preferred optimized for non-jvm)
                  - Doesn't say anything about org.jetbrains.kotlin.native.target (required 'ios_arm64')
m
are you sure the
version
should be
1.0.0
? it looks like it doens’t exist
Ohh the version is correct according to the readme, it looks like they do not share artifact for
iosArm64CompileKlibraries
you should create an issue in their Github repo