-
Notifications
You must be signed in to change notification settings - Fork 69
[만들면서 배우는 DI 5단계] 오이 미션 제출합니다. #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cucumber99
wants to merge
11
commits into
woowacourse:cucumber99
Choose a base branch
from
cucumber99:step5
base: cucumber99
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a8abd1f
docs: 5단계 기능 요구 사항 추가
cucumber99 000b7ca
build: Hilt 의존성 추가
cucumber99 062cf76
feat: `@HiltAndroidApp` 어노테이션을 통한 DI 그래프 생성
cucumber99 f6f4264
feat: Database 및 Dao 모듈 구현
cucumber99 4e7d130
feat: ProductRepository 모듈 구현
cucumber99 2c2e817
feat: Qualifier 어노테이션 추가
cucumber99 9252944
feat: CartRepository 모듈 구현
cucumber99 e3f6d18
feat: DateFormatter 생성 범위 지정 및 Context 주입
cucumber99 0f14551
feat: Repository 의존성 주입
cucumber99 15210d8
feat: Activity 및 ViewModel Hilt 적용
cucumber99 4131e6b
feat: `@Singleton` 어노테이션 추가
cucumber99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/woowacourse/shopping/data/repository/DefaultCartRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/woowacourse/shopping/data/repository/InMemoryCartRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
app/src/main/java/woowacourse/shopping/data/repository/ProductRepositoryImpl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package woowacourse.shopping.hilt | ||
|
|
||
| import javax.inject.Qualifier | ||
|
|
||
| @Qualifier | ||
| @Retention(AnnotationRetention.BINARY) | ||
| annotation class HiltInMemory | ||
|
|
||
| @Qualifier | ||
| @Retention(AnnotationRetention.BINARY) | ||
| annotation class HiltRoomDB |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/woowacourse/shopping/hilt/module/CartRepositoryModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package woowacourse.shopping.hilt.module | ||
|
|
||
| import dagger.Binds | ||
| import dagger.Module | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import woowacourse.shopping.data.repository.DefaultCartRepository | ||
| import woowacourse.shopping.data.repository.InMemoryCartRepository | ||
| import woowacourse.shopping.domain.repository.CartRepository | ||
| import woowacourse.shopping.hilt.HiltInMemory | ||
| import woowacourse.shopping.hilt.HiltRoomDB | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| abstract class CartRepositoryModule { | ||
| @Binds | ||
| @Singleton | ||
| @HiltRoomDB | ||
| abstract fun bindsDefaultCartRepository(impl: DefaultCartRepository): CartRepository | ||
|
|
||
| @Binds | ||
| @Singleton | ||
| @HiltInMemory | ||
| abstract fun inMemoryCartRepository(impl: InMemoryCartRepository): CartRepository | ||
| } |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/woowacourse/shopping/hilt/module/DatabaseModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package woowacourse.shopping.hilt.module | ||
|
|
||
| import android.content.Context | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import dagger.hilt.components.SingletonComponent | ||
| import woowacourse.shopping.data.CartProductDao | ||
| import woowacourse.shopping.data.ShoppingDatabase | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| object DatabaseModule { | ||
| @Provides | ||
| fun provideShoppingDatabase( | ||
| @ApplicationContext context: Context, | ||
| ): ShoppingDatabase = ShoppingDatabase.getInstance(context) | ||
|
|
||
| @Provides | ||
| fun provideCartProductDao(database: ShoppingDatabase): CartProductDao = database.cartProductDao() | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
app/src/main/java/woowacourse/shopping/hilt/module/ProductRepositoryModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package woowacourse.shopping.hilt.module | ||
|
|
||
| import dagger.Binds | ||
| import dagger.Module | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.android.components.ViewModelComponent | ||
| import dagger.hilt.android.scopes.ViewModelScoped | ||
| import woowacourse.shopping.data.repository.ProductRepositoryImpl | ||
| import woowacourse.shopping.domain.repository.ProductRepository | ||
|
|
||
| @Module | ||
| @InstallIn(ViewModelComponent::class) | ||
| abstract class ProductRepositoryModule { | ||
| @Binds | ||
| @ViewModelScoped | ||
| abstract fun bindProductRepository(impl: ProductRepositoryImpl): ProductRepository | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 15 additions & 9 deletions
24
app/src/main/java/woowacourse/shopping/ui/cart/DateFormatter.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,25 @@ | ||
| package woowacourse.shopping.ui.cart | ||
|
|
||
| import android.content.Context | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import dagger.hilt.android.scopes.ActivityRetainedScoped | ||
| import woowacourse.shopping.R | ||
| import java.text.SimpleDateFormat | ||
| import java.util.Date | ||
| import java.util.Locale | ||
| import javax.inject.Inject | ||
|
|
||
| class DateFormatter(context: Context) { | ||
| private val formatter = | ||
| SimpleDateFormat( | ||
| context.getString(R.string.date_format), | ||
| Locale.KOREA, | ||
| ) | ||
| @ActivityRetainedScoped | ||
| class DateFormatter | ||
| @Inject | ||
| constructor( | ||
| @ApplicationContext context: Context, | ||
| ) { | ||
| private val formatter = | ||
| SimpleDateFormat( | ||
| context.getString(R.string.date_format), | ||
| Locale.KOREA, | ||
| ) | ||
|
|
||
| fun formatDate(timestamp: Long): String { | ||
| return formatter.format(Date(timestamp)) | ||
| fun formatDate(timestamp: Long): String = formatter.format(Date(timestamp)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Room DB는 @singleton으로 제공해야 합니다
여러 인스턴스 생성 시 캐시/트랜잭션 혼란과 자원 낭비가 발생합니다. @singleton을 추가해 주세요.
적용 예:
📝 Committable suggestion
🤖 Prompt for AI Agents