【发布时间】:2021-11-08 14:58:52
【问题描述】:
我是匕首的新手。
我已经创建了实现,我在其中注入了我的构造函数,例如:
class ListItemsPagingSourceFactory @Inject constructor(
private val api: Api,
private val pageErrorsQueue: ListItemsPagingErrorsQueue
) {
}
interface Api {
fun getList(
count: Int,
offset: Int
) : ListItemResponse
我的 api 接口有错误我只想实现我的方法以供以后使用。 但是会出现如下错误:
Error: [Hilt]
public abstract interface Api {
^
当我添加 @InstallIn @EntryPoint
到 API 接口:
error: [Hilt]
@InstallIn, 'value' class is invalid or missing: @dagger.hilt.InstallIn({})
[Hilt] Processing did not complete. See error above for details.
编辑: 我有非常相似的实现,但是在我使用的地方进行改造(@Get,@Query 等)我想实现我自己的“API”,它只是从服务本地获取数据而不启动数据库的方法。 这是来自 retrofitApi 的代码
interface RetrofitApi {
@GET("data/mine")
suspend fun getDataItems(
@Query("count") count: Int,
@Query("size") size: Int
): DataItemsResponse
如何将其更改为仅接口或抽象类,它只有方法而不启动 DB => 不会在日志中出现 Dagger 尖叫。
EDIT2:
这个配置也不行。
@InstallIn
@Module(includes = [AppModule.Api::class])
class AppModule {
// interface with @Binds
@Module
interface Api {
@Binds
fun getList(
count: Int,
offset: Int
) : ListItemResponse
}
}
错误:
@Binds methods must have exactly one parameter, whose type is assignable to the return type
【问题讨论】: