Describe the bug
When you want to use Constructor DSL to create your definitions and use named() function to provide a string qualifier to the definition, it doesn't work and your app crash. However, using standard DSL, everything works just fine and as expected.
To Reproduce
Steps to reproduce the behavior:
Create some definition using Constructor DSL
In definition scope, add named() function with supplied qualifier
Request this definition with qualifier
See error
Expected behavior
Should work as standard DSL and don't crash
Koin module and version:koin-core:3.5.3
Snippet or Sample project to help reproduce
This will not work
private fun generateOkHttpClientWithoutAuthorization() =
OkHttpClient.Builder().connectTimeout(120, TimeUnit.SECONDS).readTimeout(120, TimeUnit.SECONDS)
.writeTimeout(120, TimeUnit.SECONDS).addInterceptor(
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
).build()
private fun generateRetrofit(gson: Gson, client: OkHttpClient): Retrofit {
return Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(BuildConfig.BASE_URL).build()
}
val coreDataModule = module {
singleOf(::generateOkHttpClientWithoutAuthorization) {
named("Non-Authenticated")
}
singleOf(::generateGson)
single(named("NoAuthentication")) {
generateRetrofit(
gson = get(),
client = get(named("Non-Authenticated"))
)
}
}
class AuthenticationNetworkClient(
val retrofit: Retrofit
)
val authenticationDataModule = module {
includes(coreDataModule)
single { AuthenticationNetworkClient(get(named("NoAuthentication"))) }
}
This will
private fun generateOkHttpClientWithoutAuthorization() =
OkHttpClient.Builder().connectTimeout(120, TimeUnit.SECONDS).readTimeout(120, TimeUnit.SECONDS)
.writeTimeout(120, TimeUnit.SECONDS).addInterceptor(
HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)
).build()
private fun generateRetrofit(gson: Gson, client: OkHttpClient): Retrofit {
return Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl(BuildConfig.BASE_URL).build()
}
val coreDataModule = module {
single(named("Non-Authenticated")) { generateOkHttpClientWithoutAuthorization() }
singleOf(::generateGson)
single(named("NoAuthentication")) {
generateRetrofit(
gson = get(),
client = get(named("Non-Authenticated"))
)
}
}
class AuthenticationNetworkClient(
val retrofit: Retrofit
)
val authenticationDataModule = module {
includes(coreDataModule)
single { AuthenticationNetworkClient(get(named("NoAuthentication"))) }
}
Describe the bug When you want to use Constructor DSL to create your definitions and use
named()
function to provide a string qualifier to the definition, it doesn't work and your app crash. However, using standard DSL, everything works just fine and as expected.To Reproduce Steps to reproduce the behavior:
named()
function with supplied qualifierExpected behavior Should work as standard DSL and don't crash
Koin module and version:
koin-core:3.5.3
Snippet or Sample project to help reproduce
This will not work
This will