Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ktorfit Avoids Dependency Injection with Koin for iOS #717

Closed
brsuslcn opened this issue Oct 19, 2024 · 2 comments
Closed

Ktorfit Avoids Dependency Injection with Koin for iOS #717

brsuslcn opened this issue Oct 19, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@brsuslcn
Copy link

brsuslcn commented Oct 19, 2024

Ktorfit version

2.1.0

What happened and how can we reproduce this issue?

I have correctly implemented dependency injection, and everything functions well on Android without issues. However, I am experiencing problems on iOS. I initialize Koin separately for both Android and iOS. When I remove Ktorfit from the modules, the application works fine, but it does not function correctly when Ktorfit is included.

SplashViewModel contains repository which are from ktorfit.

ss2

What did you expect to happen?

It shouldn't make problems for injection.

Is there anything else we need to know about?

`val apiModule = module {

single<AuthTokenProvider> { AuthTokenProvider(get()) }

single {
    Ktorfit.Builder()
        .httpClient {
            install(ContentNegotiation) {
                json(Json { isLenient = true; ignoreUnknownKeys = true })
            }
            install(DefaultRequest) {
                header(HttpHeaders.ContentType, ContentType.Application.Json)
            }

            install("AuthPlugin") {
                val tokenProvider: AuthTokenProvider = get()
                requestPipeline.intercept(HttpRequestPipeline.State) {
                    val token = tokenProvider.getToken()
                    if (token != null) {
                        context.headers.append(HttpHeaders.Authorization, "Bearer $token")
                    }
                }
            }
        }
        .baseUrl(BASE_URL)
        .build()
}

single<AuthService> { get<Ktorfit>().createAuthService() }
single<ComplaintService> { get<Ktorfit>().createComplaintService() }
single<AnnouncementService> { get<Ktorfit>().createAnnouncementService() }

}

fun initializeKoin(
androidViewModelModule: Module? = null
) {
startKoin {
modules(getAppModules(androidViewModelModule))
}
}

private fun getAppModules(androidViewModelModule: Module?): List {
val commonModules = listOf(repositoryModule, apiModule, viewModelModule)
return if (androidViewModelModule != null) {
commonModules + androidViewModelModule
} else {
commonModules
}
}`

@brsuslcn brsuslcn added the bug Something isn't working label Oct 19, 2024
@geworfener
Copy link

Might be related to #720, please check the root cause.

@brsuslcn
Copy link
Author

i implemented io.ktor:ktor-client-ios, and it solved. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants