I have another question: I'm using Koin Annotation...
# koin
s
I have another question: I'm using Koin Annotations. I've created a module class that mostly contains methods with named annotations. All of them return string values, and some are nullable strings.
Copy code
@Module
@ComponentScan("foo.bar.sugar")
class NetworkModule {

    @Single
    @Named("appSettingsSharedPreferences")
    fun provideAppSettings(context: Context): SharedPreferences {
        return context.getSharedPreferences(context.getString(R.string.settings_filename), Context.MODE_PRIVATE)
    }

    @Single
    @Named("appBaseURL")
    fun provideAppBaseUrl(
        context: Context,
        @Named("appSettingsSharedPreferences") sharedPref: SharedPreferences,
    ): String {
        val defaultBaseUrlValue = context.getString(R.string.settings_base_url_default)
        return sharedPref.getString(context.getString(R.string.settings_base_url_key), defaultBaseUrlValue) ?: defaultBaseUrlValue
    }

    @Single
    @Named("appDeviceToken")
    fun provideDeviceToken(
        context: Context,
        @Named("appSettingsSharedPreferences") sharedPref: SharedPreferences,
    ): String {
        val defaultDeviceTokenValue = context.getString(R.string.settings_device_token_default)
        return sharedPref.getString(context.getString(R.string.settings_device_token_key), defaultDeviceTokenValue) ?: defaultDeviceTokenValue
    }

    @Single
    @Named("appDeviceName")
    fun provideDeviceName(
        context: Context,
        @Named("appSettingsSharedPreferences") sharedPref: SharedPreferences,
    ): String? {
        return sharedPref.getString(context.getString(R.string.settings_device_name_key), null)
    }

    @Single
    @Named("appDeviceLocation")
    fun provideDeviceLocation(
        context: Context,
        @Named("appSettingsSharedPreferences") sharedPref: SharedPreferences
    ): String? {
        return sharedPref.getString(context.getString(R.string.settings_device_location_key), null)
    }

}
I'm facing an error with Koin while trying to assemble the app
Copy code
NetworkModuleGencom$viaeurope$ehub$di.kt:11:227 None of the following candidates is applicable:
@OptionDslMarker() fun <S : Any> KoinDefinition<out S>.bind(clazz: KClass<S>): KoinDefinition<out S>
@OptionDslMarker() fun <reified S : Any> KoinDefinition<out S>.bind(): KoinDefinition<out S>
Generated DSL
Copy code
single(qualifier=org.koin.core.qualifier.StringQualifier("appDeviceName")) { moduleInstance.provideDeviceName(context=get(),sharedPref=get(qualifier=org.koin.core.qualifier.StringQualifier("appSettingsSharedPreferences"))) } bind(kotlin.String::class)
	single(qualifier=org.koin.core.qualifier.StringQualifier("appDeviceLocation")) { moduleInstance.provideDeviceLocation(context=get(),sharedPref=get(qualifier=org.koin.core.qualifier.StringQualifier("appSettingsSharedPreferences"))) } bind(kotlin.String::class)
I'm trying to understand why it's happening, but checking the signature of the definitions looks fine to me 🤔
a
This is already more of a software design question and not that Koin specific
I would suggest to do that without Koin first
yeah, maybe a class DeviceInfo(val token, val name, val location) and then you don't need so much Koin
s
Without Koin the code was already working actually, and Im introducing the Koin DI framework. But Im unable to understand the error message, what's going wrong exactly
Copy code
e: file:///Users/sagarkhurana/StudioProjects/ehub-android/app/build/generated/ksp/debug/kotlin/org/koin/ksp/generated/NetworkModuleGencom$viaeurope$ehub$di.kt:11:227 None of the following candidates is applicable:
@OptionDslMarker() fun <S : Any> KoinDefinition<out S>.bind(clazz: KClass<S>): KoinDefinition<out S>
@OptionDslMarker() fun <reified S : Any> KoinDefinition<out S>.bind(): KoinDefinition<out S>
Let me know if anyone has any ideas on the above
I've raised a issue too, as its failing for the nullable return type and working for the non-nullable return type defination https://github.com/InsertKoinIO/koin/issues/2017
a
can you put it in koin-annotations repo instead?