Android
dagger 에서 koin 으로 convert
aucd29
2019. 6. 12. 11:06
dagger 에서 koin 으로 전환이 어떤지 알아보기 위해 잠시 뒤적거리고 있는데
가령 okhttp module 을 dagger 를 통해서는 library 단에 아래와 같이 구현하고
@Provides
@Singleton
fun provideLoggingInterceptor(logger: Logger) =
HttpLoggingInterceptor(HttpLoggingInterceptor.Logger {
if (logger.isDebugEnabled) {
logger.debug(it)
}
})
app 단에서 network module 을 생성해 okhttp module 을 가져다가 (includes) 쓰고 추가적으로 okhttp module 에서 사용할 logger 의 debug level 을 조정 하도록 구현해 두었는데
koin 에서는 이러한 방식이 어케 되나 했는데 일단 답은 항상 그렇듯 메뉴얼 정독!! 에 나온다!!
https://insert-koin.io/docs/2.0/documentation/reference/index.html#_koin_core_dsl_container_api
뒤적거려보니 인자를 어떻게 전달받는지 보니 java 의 lambda 형태 처럼 사용하면 되는 듯
single { (logger: Logger) ->
HttpLoggingInterceptor(HttpLoggingInterceptor.Logger {
if (logger.isDebugEnabled) {
logger.debug(it)
}
})
}
가령 okhttp module 을 dagger 를 통해서는 library 단에 아래와 같이 구현하고
@Provides
@Singleton
fun provideLoggingInterceptor(logger: Logger) =
HttpLoggingInterceptor(HttpLoggingInterceptor.Logger {
if (logger.isDebugEnabled) {
logger.debug(it)
}
})
app 단에서 network module 을 생성해 okhttp module 을 가져다가 (includes) 쓰고 추가적으로 okhttp module 에서 사용할 logger 의 debug level 을 조정 하도록 구현해 두었는데
koin 에서는 이러한 방식이 어케 되나 했는데 일단 답은 항상 그렇듯 메뉴얼 정독!! 에 나온다!!
https://insert-koin.io/docs/2.0/documentation/reference/index.html#_koin_core_dsl_container_api
뒤적거려보니 인자를 어떻게 전달받는지 보니 java 의 lambda 형태 처럼 사용하면 되는 듯
single { (logger: Logger) ->
HttpLoggingInterceptor(HttpLoggingInterceptor.Logger {
if (logger.isDebugEnabled) {
logger.debug(it)
}
})
}