-
Notifications
You must be signed in to change notification settings - Fork 7
Replace ServiceLocator by DI #1
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
Aluminiy
wants to merge
1
commit into
Otus-Android:master
Choose a base branch
from
Aluminiy:master
base: master
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
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
15 changes: 13 additions & 2 deletions
15
app/src/main/java/com/otus/dihomework/ProductsApplication.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,10 +1,21 @@ | ||
| package com.otus.dihomework | ||
|
|
||
| import android.app.Application | ||
| import com.otus.dihomework.common.di.Dependencies | ||
| import com.otus.dihomework.common.di.DependenciesProvider | ||
| import com.otus.dihomework.di.AppComponent | ||
| import com.otus.dihomework.di.DaggerAppComponent | ||
|
|
||
| class ProductsApplication : Application(), DependenciesProvider { | ||
|
|
||
| lateinit var appComponent: AppComponent | ||
|
|
||
| class ProductsApplication : Application() { | ||
| override fun onCreate() { | ||
| super.onCreate() | ||
| ServiceLocator.init(this) | ||
| appComponent = DaggerAppComponent.factory().create(this) | ||
| } | ||
|
|
||
| override fun getDependencies(): Dependencies { | ||
| return appComponent | ||
| } | ||
| } |
106 changes: 0 additions & 106 deletions
106
app/src/main/java/com/otus/dihomework/ServiceLocator.kt
This file was deleted.
Oops, something went wrong.
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
3 changes: 2 additions & 1 deletion
3
app/src/main/java/com/otus/dihomework/common/data/ProductDomainMapper.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
8 changes: 4 additions & 4 deletions
8
app/src/main/java/com/otus/dihomework/common/data/ProductRemoteDataSource.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
10 changes: 5 additions & 5 deletions
10
app/src/main/java/com/otus/dihomework/common/data/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
10 changes: 5 additions & 5 deletions
10
app/src/main/java/com/otus/dihomework/common/domain_impl/ConsumeFavoritesUseCaseImpl.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
10 changes: 5 additions & 5 deletions
10
app/src/main/java/com/otus/dihomework/common/domain_impl/ConsumeProductsUseCaseImpl.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
8 changes: 4 additions & 4 deletions
8
app/src/main/java/com/otus/dihomework/common/domain_impl/ToggleFavoriteUseCaseImpl.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
4 changes: 3 additions & 1 deletion
4
app/src/main/java/com/otus/dihomework/common/util/PriceFormatter.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,28 @@ | ||
| package com.otus.dihomework.di | ||
|
|
||
| import android.content.Context | ||
| import com.otus.dihomework.common.domain_api.ConsumeProductsUseCase | ||
| import com.otus.dihomework.common.domain_api.ToggleFavoriteUseCase | ||
| import com.otus.dihomework.features.products.ProductsStateFactory | ||
| import dagger.BindsInstance | ||
| import dagger.Component | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| @Component(modules = [NetworkModule::class, AppModule::class, SubcomponentsModule::class]) | ||
| interface AppComponent : ProductsDependencies { | ||
|
|
||
| fun favoritesComponent(): FavoritesComponent.Factory | ||
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun create(@BindsInstance context: Context): AppComponent | ||
| } | ||
|
|
||
| override fun consumeProductsUseCase(): ConsumeProductsUseCase | ||
| override fun toggleFavoriteUseCase(): ToggleFavoriteUseCase | ||
| override fun productsStateFactory(): ProductsStateFactory | ||
| } | ||
|
|
||
| @dagger.Module(subcomponents = [FavoritesComponent::class]) | ||
| interface SubcomponentsModule | ||
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,33 @@ | ||
| package com.otus.dihomework.di | ||
|
|
||
| import com.otus.dihomework.common.data.FavoritesRepositoryImpl | ||
| import com.otus.dihomework.common.data.ProductRepositoryImpl | ||
| import com.otus.dihomework.common.domain_api.ConsumeFavoritesUseCase | ||
| import com.otus.dihomework.common.domain_api.ConsumeProductsUseCase | ||
| import com.otus.dihomework.common.domain_api.ToggleFavoriteUseCase | ||
| import com.otus.dihomework.common.domain_impl.ConsumeFavoritesUseCaseImpl | ||
| import com.otus.dihomework.common.domain_impl.ConsumeProductsUseCaseImpl | ||
| import com.otus.dihomework.common.domain_impl.FavoritesRepository | ||
| import com.otus.dihomework.common.domain_impl.ProductRepository | ||
| import com.otus.dihomework.common.domain_impl.ToggleFavoriteUseCaseImpl | ||
| import dagger.Binds | ||
| import dagger.Module | ||
|
|
||
| @Module | ||
| interface AppModule { | ||
|
|
||
| @Binds | ||
| fun bindProductRepository(impl: ProductRepositoryImpl): ProductRepository | ||
|
|
||
| @Binds | ||
| fun bindFavoritesRepository(impl: FavoritesRepositoryImpl): FavoritesRepository | ||
|
|
||
| @Binds | ||
| fun bindConsumeProductsUseCase(impl: ConsumeProductsUseCaseImpl): ConsumeProductsUseCase | ||
|
|
||
| @Binds | ||
| fun bindConsumeFavoritesUseCase(impl: ConsumeFavoritesUseCaseImpl): ConsumeFavoritesUseCase | ||
|
|
||
| @Binds | ||
| fun bindToggleFavoriteUseCase(impl: ToggleFavoriteUseCaseImpl): ToggleFavoriteUseCase | ||
| } |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/otus/dihomework/di/FavoritesComponent.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,16 @@ | ||
| package com.otus.dihomework.di | ||
|
|
||
| import com.otus.dihomework.common.di.FeatureScope | ||
| import com.otus.dihomework.features.favorites.FavoritesViewModelFactory | ||
| import dagger.Subcomponent | ||
|
|
||
| @FeatureScope | ||
| @Subcomponent | ||
| interface FavoritesComponent { | ||
| fun viewModelFactory(): FavoritesViewModelFactory | ||
|
|
||
| @Subcomponent.Factory | ||
| interface Factory { | ||
| fun create(): FavoritesComponent | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/otus/dihomework/di/FavoritesDependencies.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,12 @@ | ||
| package com.otus.dihomework.di | ||
|
|
||
| import com.otus.dihomework.common.di.Dependencies | ||
| import com.otus.dihomework.common.domain_api.ConsumeFavoritesUseCase | ||
| import com.otus.dihomework.common.domain_api.ToggleFavoriteUseCase | ||
| import com.otus.dihomework.features.favorites.FavoritesStateFactory | ||
|
|
||
| interface FavoritesDependencies : Dependencies { | ||
| fun consumeFavoritesUseCase(): ConsumeFavoritesUseCase | ||
| fun toggleFavoriteUseCase(): ToggleFavoriteUseCase | ||
| fun favoritesStateFactory(): FavoritesStateFactory | ||
| } |
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.
эти
overrideне нужны