【发布时间】:2022-01-04 21:30:30
【问题描述】:
我在我的应用模块中使用来自外部模块的AuthenticationRequest 对象。我将此对象作为对我的 AccountRepository 的依赖项提供。这就是我在 app 模块中定义依赖项的方式。
@InstallIn(SingletonComponent::class)
@Module
class ApplicationModule {
@Provides
@Singleton
fun provideRepository(
authenticationRequest: AuthenticationRequest,
accountDao: AccountDao
) = AccountRepository(authenticationRequestFactory, accountDao)
}
外部模块中AuthenticationRequest的构造函数:
class AuthenticationRequest(
api: AuthenticationApi,
apiError : ApiError = ApiErrorImpl()
) : Request<AuthenticationApi>(api, apiError)
还有 AccountRepository:
class AccountRepository @Inject constructor(
private val authenticationRequestFactory: AuthenticationRequestFactory,
private val accountDao: AccountDao
) {....}
但我收到以下错误消息: Dagger/MissingBinding] com.external.auth.AuthenticationRequest 不能在没有@Inject 构造函数或@Provides-annotated 方法的情况下提供。
如何正确注入AuthenticationRequest 对象?请注意,定义此对象的模块不使用 Dagger-Hilt。它虽然使用 Dagger-2。任何指针都会很棒。
注意:项目结构是
|-- :app
-- :external module
【问题讨论】:
标签: android dagger-2 dagger-hilt