Nicolas Patin
04/17/2026, 10:38 AMCompositionLocalProvider(LocalSdkExport provides koinInject())
My SdkExport is injected dynamically at start using:
singleSdkExport { sdkExport }
I have a missing definition error when compileSafety is enabled, and it seems I can't add a @Provided in a composable variable.
What is the best way to handle this case ? ThanksNicolas Patin
04/17/2026, 10:47 AMsdkExport to my Composable method (which is the MainViewController used from the SwiftUI application in a CMP project) but I hoped that I could reuse my previously injected valueAlexandru Caraus
04/17/2026, 11:35 AMAlexandru Caraus
04/17/2026, 11:37 AMAlexandru Caraus
04/17/2026, 11:47 AM// Top-level / screen composable โ Koin boundary
@Composable
fun MyScreen(
sdkExport: SdkExport = koinInject()
) {
MyContent(sdkExport)
}Nicolas Patin
04/17/2026, 11:58 AMCompositionLocalProvider ).
It also has some methods that are called in some ViewModels which explains why I need to inject it using Koin tooAlexandru Caraus
04/17/2026, 1:08 PMNicolas Patin
04/17/2026, 1:18 PM:shared module.
I need to use an external SDK which is a Video Feed View which does not have a CMP library.
I created an :external-video-player module which has the following signature in commonMain :
@Composable
public expect fun VideoFeed(
modifier: Modifier = Modifier,
id: String,
)
On iosMain, I have:
public val LocalVideoFeedExport: ProvidableCompositionLocal<VideoFeedExport> = staticCompositionLocalOf {
error("VideoFeedExport not initialized")
}
public interface VideoFeedExport {
public fun createVideoFeedView(): UIView
// and other methods for the SDK management called in the ViewModel
}
@Composable
public actual fun VideoFeed(
modifier: Modifier,
id: String,
) {
val export = LocalVideoFeedExport.current
UIKitView(
modifier = modifier.fillMaxSize(),
factory = {
export.createVideoFeedView()
},
)
}
That allows me to simply implement this interface in my iosApp target by adding the VideoFeedSDKAlexandru Caraus
04/17/2026, 1:31 PMAlexandru Caraus
04/17/2026, 1:31 PMcommmon/
@Composable
public expect fun VideoFeed(
modifier: Modifier = Modifier,
id: String,
)
iosMain/
public interface VideoFeedExport {
public fun createVideoFeedView(): UIView
// and other methods for the SDK management called in the ViewModel
}
@Composable
public actual fun VideoFeed(
modifier: Modifier,
id: String,
) {
val export = koinInject<VideoFeedExport>()
UIKitView(
modifier = modifier.fillMaxSize(),
factory = {
export.createVideoFeedView()
},
)
}
somewhere in iosMain/
@Factory or @Single
fun provideVideoFeed(videoSdk:VideoSdk) = VideoFeedExportImpl(videoSdk)
also in common of the ^^(same) module need to have a
@Module
@ComponentScan("your.package")
@Configuration
VideoFeedWhateverNicolas Patin
04/17/2026, 1:36 PMVideoFeed stuff is not in my `shared`module, it's in a module without Koin (it's not even local to my project because we share this video feed library across multiple projects)Nicolas Patin
04/17/2026, 1:36 PMkoinInject util method in the iosMain VideoFeed methodAlexandru Caraus
04/17/2026, 1:37 PMNicolas Patin
04/17/2026, 1:38 PMkoinInjectProvided() which allows us to specify that the injected value should not be considered by the compile safety flagAlexandru Caraus
04/17/2026, 1:42 PMAlexandru Caraus
04/17/2026, 1:46 PMAlexandru Caraus
04/17/2026, 1:47 PMAlexandru Caraus
04/17/2026, 1:47 PMNicolas Patin
04/17/2026, 1:51 PM@Provided in a class, function or value parameter.Alexandru Caraus
04/17/2026, 1:53 PMAlexandru Caraus
04/17/2026, 1:54 PMAlexandru Caraus
04/17/2026, 1:54 PMAlexandru Caraus
04/17/2026, 1:54 PMAlexandru Caraus
04/17/2026, 1:55 PMNicolas Patin
04/17/2026, 1:57 PMNicolas Patin
04/17/2026, 1:57 PMNicolas Patin
04/17/2026, 2:06 PMAlexandru Caraus
04/17/2026, 2:09 PMNicolas Patin
04/17/2026, 2:09 PMAlexandru Caraus
04/17/2026, 2:10 PM