๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋นˆ ๊ตฌ๋ฉ ์ฑ„์šฐ๊ธฐ

[Hilt] @Qualifier

https://salmonpack.tistory.com/51

 

[Android] Hilt @Qualifier - Retrofit ์„œ๋กœ๋‹ค๋ฅธ baseUrl ๊ตฌ๋ถ„ํ•˜๊ธฐ

์˜ค๋Š˜์˜ ์ฃผ์ œ๋Š” ๋ฐ”๋กœ Hilt๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Retorfit์„ ์‚ฌ์šฉํ•  ๋•Œ baseUrl์ด ๋‹ค๋ฅธ ๋‘ ์ข…๋ฅ˜์˜ Retrofit Builder๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ž…๋‹ˆ๋‹ค. Android Hilt ์ ์šฉํ•˜๊ธฐ2 (@Binds, @Provides, @ApplicationContext) Photo by Anis Rahman on Unsplash ํ”„

salmonpack.tistory.com

 

https://smg7.tistory.com/22

 

Hilt - @Provides, @Qualifier

@Provides๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šค ์‚ฝ์ž… ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ์œ ํ˜•์„ ์ƒ์„ฑ์ž ์‚ฝ์ž…ํ•  ์ˆ˜ ์—†๋Š” ์œ ์ผํ•œ ๊ฒฝ์šฐ๋Š” ์•„๋‹™๋‹ˆ๋‹ค. ํด๋ž˜์Šค๊ฐ€ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ œ๊ณต๋˜๋ฏ€๋กœ ํด๋ž˜์Šค๋ฅผ ์†Œ์œ ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ(Retrofit, OkHttpCl

smg7.tistory.com

 

๊ฐ™์€ ํƒ€์ž…์ด์ง€๋งŒ, ๋ถ„๋ช…ํžˆ ๋‹ค๋ฅธ ์ธ์Šคํ„ด์Šค๋“ค์„ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•ด ์“ฐ๋Š” ์–ด๋…ธํ…Œ์ด์…˜

 

๋„ค์ด๋ฒ„ ๊ฒ€์ƒ‰ API, ์นด์นด์˜ค ๊ฒ€์ƒ‰ API์šฉ ๋ ˆํŠธ๋กœํ• ์„œ๋น„์Šค๋“ค์„ Hilt๋กœ Module ์•ˆ์— ์ž‘์„ฑํ•˜๊ณ  ๋‚˜์„œ, Hilt๋Š” Naver์šฉ๊ณผ Kakao์šฉ์„ ๊ตฌ๋ถ„ํ•˜์ง€ ๋ชปํ•œ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ์•˜๋‹ค.

 

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class NaverServcie

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class KakaoService

๋‘ ๊ฐ€์ง€ ๊ตฌ๋ถ„์ž๋กœ ์“ธ ์ˆ˜ ์žˆ๋Š” ์‹๋ณ„์ž์šฉ์œผ๋กœ ๋‘ ๊ฐœ ๋งŒ๋“ค๊ณ 

 

@Provides
@Singleton
@NaverService
fun provideNaverHeaderInterceptor() ...

@Provides
@Singleton
@KakaoService
fun provideKakaoHeaderInterceptor() ...

@Provides
@Singleton
@NaverService
fun provideNaverHttpClient(@NaverService naverHaedreInterceptor) ...

@Provides
@Singleton
@KakaoService
fun provideKakaoHttpClient(@KakaoService kakaoHaedreInterceptor) ...

...

์š” ๋‘ ๊ฐ€์ง€ ์–ด๋…ธํ…Œ์ด์…˜์„ ์—ฌ๋Ÿฌ ํƒ€์ž…์˜ ์ธ์Šคํ„ด์Šค์˜ ๊ฒฝ์šฐ์—๋„ ์žฌ์‚ฌ์šฉํ•˜๋ฉด ์ž˜ ์ผ๋‹ค.