ContributesAndroidInjector in a Subcomponent
See original GitHub issueIs there a way to add ContributesAndroidInjector
for activity in a Subcomponent? I am trying to create a scope that works across a few activities.
What I have is this:
AppComponent
@Component(modules = [
AndroidInjectionModule::class,
AndroidSupportInjectionModule::class
])
interface AppComponent: AndroidInjector<DaggerApplication> {
override fun inject(instance: DaggerApplication)
fun chatComponent(): ChatComponent.Builder
fun inject(needle: Needle)
@Component.Builder
interface Builder {
@BindsInstance
fun application(application: Application): AppComponent.Builder
fun build(): AppComponent
}
}
ChatScope
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class ChatScope
ChatComponent
@Subcomponent(modules = [ChatBindingModule::class])
@ChatScope
interface ChatComponent {
@Subcomponent.Builder
interface Builder {
fun chatModule(chatModule: ChatModule): Builder
fun build(): ChatComponent
}
}
ChatBindingModule
@Module
abstract class ChatBindingModule {
@ActivityScoped
@ContributesAndroidInjector(modules = [])
abstract fun chatListActivity(): ChatListActivity
@ActivityScoped
@ContributesAndroidInjector(modules = [])
abstract fun chatDetailActivity(): ChatDetailActivity
}
With this code dagger fails to find injector for both activities. I guess I do know why that is happening but no idea how to solve this problem
Issue Analytics
- State:
- Created 5 years ago
- Comments:7
Top Results From Across the Web
Dagger subcomponent with contributor - Stack Overflow
@ContributesAndroidInjector.modules is a way for talking to the generated subcomponent. So the relationship between Activity and FeatureFragment ...
Read more >Dagger 2 with ContributesAndroidInjector - Is it easy? - Medium
The injector is implemented with a dagger. Subcomponent and will be a child of the dagger. Module's component.
Read more >ContributesAndroidInjector - Dagger
Generates an AndroidInjector for the return type of this method. The injector is implemented with a Subcomponent and will be a child of...
Read more >Dagger 2 Annotations: @Binds & @ContributesAndroidInjector
Dagger Android introduced an annotation which can reduce the Component Binds IntoSet Subcomponent ActivityKey FragmentKey etc. boilerplate for ...
Read more >Dagger by Tutorials, Chapter 16: Dagger & Android | Kodeco ...
When to use @Component s or @Subcomponent s to manage dependencies between objects with different @Scope s. ... How to use @ContributesAndroidInjector ....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’d need to provide custom code in your Application instance that would know how to access ChatComponent. Something like this:
It seems there is no elegant way of doing this, so at the end I implemented it with standard Dagger approach