This file contains 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
-@MyFeatureScope | |
-class CityRepoImpl @Inject constructor(val app: Application) : CityRepo { | |
+class CityRepoImpl(val app: Application) : CityRepo { | |
override suspend fun getCurrentCity(): String = | |
//... | |
} | |
@Module | |
-abstract class MyFeatureModule { | |
- @Binds |
This file contains 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
@Module | |
class CoreModule { | |
@Provides | |
@Singleton | |
fun providePrefs(app: Application): SharedPreferences = | |
PreferenceManager.getDefaultSharedPreferences(app) | |
} | |
@Singleton | |
@Component(modules = [CoreModule::class]) |
This file contains 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
@MyFeatureScope | |
@Component(modules = [MyFeatureModule::class], dependencies = [CoreComponent::class]) | |
interface MyFeatureComponent { | |
val prefs: SharedPreferences | |
val repo: CityRepo | |
} |
This file contains 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
interface CityRepo { | |
suspend fun getCurrentCity(): String | |
} | |
@MyFeatureScope | |
class CityRepoImpl @Inject constructor(val app: Application) : CityRepo { | |
override suspend fun getCurrentCity(): String = | |
//... | |
} |
This file contains 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
@Module | |
abstract class MyFeatureModule { | |
@Binds | |
abstract fun bindCityRepo(impl: CityRepoImpl): CityRepo | |
} |
This file contains 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
class MyViewModel @Inject constructor( | |
private val repo: CityRepo | |
) : ViewModel() { | |
//... | |
} |
This file contains 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
@MyActivityScope | |
@Component(dependencies = [MyFeatureComponent::class]) | |
interface MyActivityComponent { | |
fun inject(activity: MyActivity) | |
} | |
class MyActivity : AppCompatActivity() { | |
@Inject | |
lateinit var viewModelProvider: Provider<MyViewModel> |
This file contains 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
class CityRepoImpl(val app: Application) : CityRepo { | |
override suspend fun getCurrentCity(): String = | |
//... | |
} |
This file contains 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
@Module | |
class MyFeatureModule { | |
@Provides | |
@MyFeatureScope | |
fun provideCityRepo(app: Application): CityRepo = CityRepoImpl(app) | |
} |
This file contains 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
class MyViewModel( | |
private val repo: CityRepo | |
) : ViewModel() { | |
//... | |
} |