Skip to content

Android Team Tech Stack

Gimun Kim edited this page Sep 27, 2024 · 5 revisions

Dependency Injection

1. ํ™œ์šฉ ๊ธฐ์ˆ 

1-1. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ช…

  • Dagger-Hilt

1-2. ๋ฒ„์ „

  • 2.51.1

2. ํ™œ์šฉ ๋ชฉ์ 

์•ˆ๋“œ๋กœ์ด๋“œ ํ”„๋ ˆ์ž„์›Œํฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์—์„œ ์•ˆ๋“œ๋กœ์ด๋“œ ์ฃผ์š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋น„๋กฏํ•œ ๊ฐ์ฒด๋“ค์— ์˜์กด์„ฑ์„ ์ž๋™์œผ๋กœ ์ฃผ์ž…ํ•˜๊ธฐ ์œ„ํ•จ


3. ๊ธฐ์ˆ  ์„ ํƒ ์ด์œ 

3-1. ์ปดํŒŒ์ผ ํƒ€์ž„ ์ฃผ์ž…์˜ ์„ฑ๋Šฅ ์ƒ ์ด์ 

  • ์•ˆ์ •์„ฑ

    • ์ปดํŒŒ์ผ ํƒ€์ž„์— ์˜์กด์„ฑ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ตฌ์ถ•ํ•˜๊ณ  ๊ฒ€์ฆํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋Ÿฐํƒ€์ž„์—์„œ์˜ ์˜ค๋ฅ˜ ๊ฐ€๋Šฅ์„ฑ ์ถ•์†Œ
  • ์†๋„

    • ์ปดํŒŒ์ผ ํƒ€์ž„ ์ฒ˜๋ฆฌ๋ฅผ ํ†ตํ•ด ๋Ÿฐํƒ€์ž„์— ์ง„ํ–‰ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์•ฑ ์‹คํ–‰ ์†๋„ ์ƒ ์ด์  ํ™•๋ณด ๊ฐ€๋Šฅ

3-2. ์‚ฌ์šฉ ๋ฐฉ์‹์—์„œ์˜ ์ด์ 

Annotation ์‚ฌ์šฉ์˜ ๋†’์€ ๋ช…์‹œ์„ฑ

  • ์–ด๋…ธํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜์œผ๋กœ ์˜์กด์„ฑ ์ฃผ์ž… ๋ฐฉ์‹์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐฉ์‹์˜ ์žฅ์ 

    • ํ•„์š”ํ•œ ๊ณณ์— ์–ด๋…ธํ…Œ์ด์…˜๋งŒ ์ถ”๊ฐ€ํ•˜๋ฉด ์˜์กด์„ฑ ์ฃผ์ž…์ด ์ž๋™์œผ๋กœ ์ด๋ค„์ง
    • ์ •ํ•ด์ง„ ์–ด๋…ธํ…Œ์ด์…˜๋งŒ ์ถ”๊ฐ€ํ•˜๋ฉด ๋˜๋ฏ€๋กœ, ๊ฐœ๋ฐœ์ž๊ฐ€ ๋ช…ํ™•ํ•œ ๊ธฐ์ค€์œผ๋กœ ์ฃผ์ž… ๊ตฌ์กฐ๋ฅผ ์ •์˜ ๊ฐ€๋Šฅ
  • ๋‹ค๋ฅธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ Koin ์ฃผ์ž… ๋ฐฉ์‹ : DSL ๊ธฐ๋ฐ˜ ํ•จ์ˆ˜ ์„ ์–ธ

    • Koin๊ณผ ๋น„๊ตํ•˜์˜€์„ ๋•Œ, ์–ด๋…ธํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜์ด ๋†’์€ ๊ฐ€๋…์„ฑ์„ ๊ฐ€์ง„๋‹ค๊ณ  ํŒ๋‹จ

3-3. ์‚ฌ์šฉ ๊ฒฝํ—˜

์ˆ™๋‹ฌ๋„๊ฐ€ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ๋น ๋ฅธ ๊ตฌํ˜„ ์ถ”๊ตฌ


4. ์ ์šฉ

4-1. Module

4-1-1. Module ๊ตฌ์„ฑ

  • Remote

    • NetworkModule
  • Local

    • DatabaseModule
    • DataStoreModule
  • Data Source

    • DataSourceModule
  • Repository

    • RepositoryModule

4-1-2. Module ์ •์˜ ๋ฐฉ์‹

  • ๋ชจ๋“ˆ์„ object๋กœ ์ •์˜ํ•˜๊ณ  ๋‚ด๋ถ€์— @Provides ํ•จ์ˆ˜ ์ •์˜

    โ†’ ํ•„์š”ํ•œ ์˜์กด์„ฑ ์ƒ์„ฑ ์‹œ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ, ๊ตฌ์ฒด์ ์ธ ๊ตฌํ˜„์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜ ์ •์˜

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    @Provides
    @Singleton
    fun provideRecipeDatabase(
        @ApplicationContext context: Context,
    ): RecipeDatabase = RecipeDatabase.getInstance(context)

    @Provides
    @Singleton
    fun provideRecipeStepDao(recipeDatabase: RecipeDatabase): RecipeStepDao = recipeDatabase.recipeStepDao()
}

  • ๋ชจ๋“ˆ์„ interface๋กœ ์ •์˜ํ•˜๊ณ  ๋‚ด๋ถ€์— @Binds ํ•จ์ˆ˜ ์ •์˜

    โ†’ ๊ฐ์ฒด์— ํ•„์š”ํ•œ ์˜์กด์„ฑ์ด ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ

@Module
@InstallIn(SingletonComponent::class)
interface DataSourceModule {
    @Binds
    fun bindAuthorizationRemoteDataSource(
        defaultAuthorizationRemoteDataSource: DefaultAuthorizationRemoteDataSource,
    ): AuthorizationRemoteDataSource

    @Binds
    fun bindSessionLocalDataSource(defaultSessionLocalDataSource: DefaultSessionLocalDataSource): SessionLocalDataSource
}

4-2. ์ƒ๋ช…์ฃผ๊ธฐ ๊ด€๋ฆฌ

  • ๋ชจ๋“  ์˜์กด์„ฑ์„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ „์—ญ์˜ ์ƒ๋ช…์ฃผ๊ธฐ ๋™์•ˆ ์‹ฑ๊ธ€ํ†ค์œผ๋กœ ์‚ฌ์šฉ ์ค‘

    • DataSource, Repository, Database, Network ๊ด€๋ จ ๊ฐ์ฒด๋“ค
  • ๊ฐ ์ปดํฌ๋„ŒํŠธ์˜ ์˜์กด์„ฑ์— ๋งž๊ฒŒ ์ƒ๋ช…์ฃผ๊ธฐ๋ฅผ ๊ด€๋ฆฌํ•  ํ•„์š”์„ฑ ๋–จ์–ด์ง

    • ๋ฐ์ดํ„ฐ ๋ ˆ์ด์–ด์— ์กด์žฌํ•˜๋Š” ๊ฐ์ฒด๋“ค๋งŒ์„ ํƒ€ ๊ฐ์ฒด์— ์ฃผ์ž…
    • ํ•ด๋‹น ๊ฐ์ฒด๋“ค์€ ์–ด๋Š ํ™”๋ฉด์—์„œ๋‚˜ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Œ โ†’ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ƒ๋ช…์ฃผ๊ธฐ ์ „์—ญ์—์„œ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ฒฐ์ •