-
Let's say I have two gradle modules: When using Dagger I could have both of them defined as subcomponent and have // in module ":login"
@Subcomponent
interface LoginComponent {
// ...
}
// in module ":app" which depends on ":login"
@Subcomponent
interface AppComponent {
fun loginComponent(): LoginComponent
}
fun main() {
val appComponent = DaggerAppComponent()
val loginComponent = appComponent.loginComponent()
} Notice that in this setup the It seems that I can't do this setup in LoginComponent(parent = AppComponent()) and so gradle dependency is reverted too: I understand that this can be resolved by having Did I miss something perhaps? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
An interface would be the suggested way to do this, yes. // base module
interface AppComponent
// feature module
@Component abstract class LoginComponent(@Component val parent: AppComponent)
// app module
@Component abstract class AppComponentImpl : AppComponent There's a few reasons it's done in this direction but the biggest on is it straight-forwardly maps to the generated code where LoginComponent needs to reference AppComponent in some way to grab dependencies. It shouldn't be more tedious than any other cases where you define an interface in base for your features to use that's implemented in app? |
Beta Was this translation helpful? Give feedback.
An interface would be the suggested way to do this, yes.
There's a few reasons it's done in this direction but the biggest on is it straight-forwardly maps to the generated code where LoginComponent needs to reference AppComponent in some way to grab dependencies.
It shouldn't be more tedious than any other cases where you define an interface in base for your features to use that's implemented in app?