android / codelab-android-dagger-to-hilt

Apache License 2.0
93 stars 36 forks source link

Using library gradle module DependencyComponent as a dependency for Hilt ApplicationComponent #6

Open ultraon opened 3 years ago

ultraon commented 3 years ago

Hello, I tried finding a solution to connect the existing library DependencyComponent to Hilt ApplicationComponent. It looks like it is impossible at the moment. Could you please clarify that.

Example: we have the following gradle modules structure:

// from feature1 lib module
interface Feature1DependencyComponent {
  val feature1Api: Feature1Api
}

// from app module
@Component(
  dependencies = [Feature1DependencyComponent::class],
  modules = [AppModule1::class, AppModule2::class]
)
@Singleton
interface ApplicationComponent {
  val feature1Api: Feature1Api // to have explicit exposing
}

As you can see @Module can't be used in feature1 because it doesn't know anything about ApplicationComponent to use with @InstallIn.

Question: how to connect Feature1DependencyComponent without using @BindsInstance to Hilt ApplicationComponent?