mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 13:27:03 +05:30
refactor(database): disallow injection of raw database types
This commit is contained in:
parent
5bd37a837c
commit
e06a8ba236
3 changed files with 24 additions and 3 deletions
|
@ -26,7 +26,7 @@ object DatabaseModule {
|
||||||
|
|
||||||
private const val LOBSTERS_DATABASE_NAME = "SavedPosts.db"
|
private const val LOBSTERS_DATABASE_NAME = "SavedPosts.db"
|
||||||
|
|
||||||
@Provides
|
@[Provides InternalDatabaseApi]
|
||||||
fun provideDatabase(@ForScope(ApplicationScope::class) context: Context): LobstersDatabase {
|
fun provideDatabase(@ForScope(ApplicationScope::class) context: Context): LobstersDatabase {
|
||||||
val driver =
|
val driver =
|
||||||
AndroidSqliteDriver(
|
AndroidSqliteDriver(
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Harsh Shandilya.
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*/
|
||||||
|
package dev.msfjarvis.claw.database.injection
|
||||||
|
|
||||||
|
import javax.inject.Qualifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Neato workaround for not allowing the [dev.msfjarvis.claw.database.LobstersDatabase] type to be
|
||||||
|
* used directly by modules that depend on this one, as we prefer them to use the specific types
|
||||||
|
* from [QueriesModule] instead. A [Qualifier] applied to the
|
||||||
|
* [dev.msfjarvis.claw.database.LobstersDatabase] type makes all injection sites require it as well,
|
||||||
|
* and marking the annotation class' visibility as `internal` lets it stay visible to the Java code
|
||||||
|
* generated by Dagger but inaccessible by the Kotlin code we're writing ourselves.
|
||||||
|
*/
|
||||||
|
@Qualifier @Retention(AnnotationRetention.RUNTIME) internal annotation class InternalDatabaseApi
|
|
@ -19,12 +19,14 @@ import dev.msfjarvis.claw.database.local.SavedPostQueries
|
||||||
object QueriesModule {
|
object QueriesModule {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideSavedPostsQueries(database: LobstersDatabase): SavedPostQueries {
|
fun provideSavedPostsQueries(@InternalDatabaseApi database: LobstersDatabase): SavedPostQueries {
|
||||||
return database.savedPostQueries
|
return database.savedPostQueries
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun providePostCommentsQueries(database: LobstersDatabase): PostCommentsQueries {
|
fun providePostCommentsQueries(
|
||||||
|
@InternalDatabaseApi database: LobstersDatabase
|
||||||
|
): PostCommentsQueries {
|
||||||
return database.postCommentsQueries
|
return database.postCommentsQueries
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue