https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Ahmad Hassan

03/27/2023, 7:27 AM
Hi, how can we inject dependencies in Composable in compose multiplatform?
🧵 1
🤔 1
d

darkmoon_uk

03/27/2023, 8:38 AM
There are two major ways to get objects into a Composable, including objects ones might classify as 'dependencies': Function parameter, Composition Local.
a

Ahmad Hassan

03/27/2023, 8:45 AM
Can you share any sample?
m

mbonnin

03/27/2023, 12:14 PM
I guess you're looking for koin or kotlin-inject?
a

Ahmad Hassan

03/27/2023, 12:16 PM
koin
@mbonnin
d

darkmoon_uk

03/28/2023, 12:37 PM
@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

Ahmad Hassan

03/28/2023, 12:39 PM
Well, it’s for Jetpack Compose. I want to use it in JetBrains Compose.
d

darkmoon_uk

03/28/2023, 12:40 PM
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

Ahmad Hassan

03/28/2023, 12:42 PM
No, I don’t want to be spoonfed. I already check docs, internet but have not found any material
d

darkmoon_uk

03/28/2023, 12:42 PM
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

Mustafa Ozhan

03/28/2023, 12:43 PM
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

darkmoon_uk

03/28/2023, 12:44 PM
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

mbonnin

03/28/2023, 12:59 PM
+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

darkmoon_uk

03/28/2023, 1:02 PM
🔍 https://insert-koin.io/docs/reference/koin-compose/multiplatform ...must have missed this one @Ahmad Hassan 😅
m

mbonnin

03/28/2023, 1:10 PM
Nice!
d

darkmoon_uk

03/28/2023, 1:13 PM
...and go team Koin! K K
m

mbonnin

03/28/2023, 1:20 PM
a

Ahmad Hassan

03/29/2023, 6:09 AM
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

Mustafa Ozhan

03/29/2023, 9:15 AM
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
13 Views