Я пытался связать зависимости следующим образом
fun getKodeinConfigurationsGraph(context: Context, url: String) = Kodein.lazy {
import(dataBaseModule(context))
import(retrofitModule(url))
bind<ConfigurationsService>() with provider { instance<RetrofitHandler>().buildCall(ConfigurationsService::class) }
import(getConfigurationRepository<Contact>(ConfigurationDataType.CONTACT))
}
fun <T> getConfigurationRepository(type: ConfigurationDataType) =
Kodein.Module {
bind<BaseDao<Contact>>() with provider { instance<AppDatabase>().getContactDao() }
bind<LocalDataSource<T>>() with provider { LocalDataSourceImpl<T>(dao = instance()) }
bind<BaseRestHandler<List<T>>>() with provider { ConfigurationsHandler<T>(configurationsService = instance(), type = type) }
bind<RemoteDataSource<List<T>>>() with provider { RemoteDataSourceImpl<List<T>>(restHandler = instance()) }
bind<Repository<T>>() with provider { BasicRepository<T>(localDataSource = instance(), remoteDataSource = instance()) }
}
Но я получил следующую ошибку
java.lang.IllegalArgumentException: bind<LocalDataSource<T>>() uses a type variable named T, therefore, the bound value can never be retrieved.
Я хотел импортировать модуль и получить необходимую зависимость без необходимости повторять одни и те же привязки каждый раз.
Есть ли способ сделать это?
Попробуйте перейти на inline fun <reified T> getConfigurationRepository(...). Тогда он будет работать точно так же, как если бы вы каждый раз повторяли bind. См. Документацию в https://kotlinlang.org/docs/reference/inline-functions.html.
Сам bind также использует параметры овеществленного типа.