I have an AppComponent with bindings, which requir...
# kotlin-inject
h
I have an AppComponent with bindings, which require a provider for a database instance. Since I'm using SQLDelight, I need to provide a unique DriverFactory instance for each platform, which I'm doing so with a child PlatformComponent, but it doesn't seem like the provider's being passed up to the parent. What is it I'm doing wrong?
[ksp] Cannot find an @Inject constructor or provider for: com.harnick.troupetent.database.PersistentStorage
Copy code
@Scope
annotation class Singleton

@Singleton
@Component
abstract class AppComponent {

    @Provides
    fun ktorClient(): HttpClient = HttpClient()

    @Provides
    fun SettingsRepoImpl.bind(): SettingsRepo = this

    @Provides
    fun StatRepoImpl.bind(): StatRepo = this
}
Copy code
expect abstract class PlatformComponent {
    fun createDb(): PersistentStorage
}
Copy code
@Component
actual abstract class PlatformComponent(
    @Component val appComponent: AppComponent,
    @get:Provides protected val appContext: Application
) {
    @Provides
    actual fun createDb(): PersistentStorage = createDatabase(DriverFactory(appContext))
}
e
You can only look up for dependencies not down. This prevents memory leaks when the parent scope is larger than the child. You could invert the ordering of your components here, or make PlatformComponent and interface AppComponent implements
h
I require constructor parameters, so couldn't use an interface, but I inverted the ordering as you mentioned and it works fine. Thank you!