我尝试通过以下方式绑定依赖项
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.
我想导入模块并获得所需的依赖项,而无需每次都重复相同的绑定。
有没有办法做到这一点?