0

我对存储库模式的使用有一个抽象,我无法进行改造调用。

我将从改造服务转到我的用例。

我有 AuthenticationRetrofitService

interface AuthenticationRetrofitService {

    @GET(LOGIN_PATH)
    suspend fun doLogin(@Header("Authorization") basicAuth: String) : Either<Throwable, Monitor>

    @GET(LOGOUT_PATH)
    suspend fun doLogout() : Either<Throwable,Unit>

    companion object {
        private const val LOGIN_PATH = "login/"
        private const val LOGOUT_PATH = "logout/"
    }
}

然后我有AuthenticationRetrofitApi哪些实现AuthenticationApi

class AuthenticationRetrofitApi(private val service: AuthenticationRetrofitService) : AuthenticationApi {

    override suspend fun doLogin(basicAuth: String) = service.doLogin(basicAuth)

    override suspend fun doLogout() = service.doLogout()

}

那么这是AuthenticationApi

interface AuthenticationApi {

    suspend fun doLogin(basicAuth: String) : Either<Throwable, Monitor>
    suspend fun doLogout() : Either<Throwable, Unit>
}

然后我有AuthenticationRepository

interface AuthenticationRepository {

    suspend fun doLogin(basicAuth: String): Either<Throwable, Monitor>
    suspend fun doLogout(): Either<Throwable, Unit>
}

AuthenticationRepositoryImpl

class AuthenticationRepositoryImpl (private val api: AuthenticationApi) : AuthenticationRepository {
    override suspend fun doLogin(basicAuth: String) =
        api.doLogin(basicAuth = basicAuth)
            .fold({
                Either.Left(Throwable())
            },
                {
                    Either.Right(it)
                }
            )

    override suspend fun doLogout() = api.doLogout().fold({Either.Left(Throwable())},{Either.Right(Unit)})

}

从我的用例中,我称AuthenticationRepository我的问题是,我不知道如何链接它们,因为如果我运行应用程序,我会收到此错误。

java.lang.IllegalArgumentException:需要 HTTP 方法注释(例如,@GET、@POST 等)。

然后我正在使用Kodein依赖注入,但我不知道要做什么bindprovide可能是什么错误?因为 :

AuthenticationRetrofitApi未使用 AuthenticationRepositoryImpl未使用

我错过了什么?

编辑

这就是我Kodein用于改造模块的方式

val retrofitModule = Kodein.Module("retrofitModule") {

    bind<OkHttpClient>() with singleton {
        OkHttpClient().newBuilder().build()
    }
    bind<Retrofit>() with singleton {
        Retrofit.Builder()
            .baseUrl("https://127.0.0.1/api/")
            .client(instance())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

//I'm not sure if I have to bind this
   bind<AuthenticationRepository>() with singleton {
        instance<Retrofit>().create(AuthenticationRepository::class.java)
    }
}
4

0 回答 0