Last active
October 29, 2019 19:50
-
-
Save manuelvicnt/4aa85080c217bfeffa9c73ed6699f349 to your computer and use it in GitHub Desktop.
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
@Singleton | |
@Component(modules = [FeedCacheModule::class, DatabaseModule::class]) | |
interface AppComponent { ... } | |
@Module | |
object FeedCacheModule { | |
@Provides | |
fun feedCache(feedDatabase: FeedDatabase): FeedCache { | |
return RoomFeedCache(database.feedDao()) | |
} | |
} | |
@Module | |
object DatabaseModule { | |
@Provides | |
@Singleton | |
fun providesDatabase(context: Context): FeedDatabase { | |
return Room.databaseBuilder( | |
context, | |
FeedDatabase::class.java, | |
DATABASE_NAME | |
).build() | |
} | |
} | |
// Other options: If DB is always needed but the FeedCache doesn't need to be always available | |
@Singleton | |
@Component(modules = [DatabaseModule::class]) | |
interface AppComponent { ... } | |
@Subcomponent(modules = [FeedCacheModule::class]) | |
interface FeedComponent { ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment