Dagger2 component with more than one dependencies

后端 未结 5 1347
轻奢々
轻奢々 2021-01-04 09:24

This is what I currently have and it works:

@FragmentScope
@Component(dependencies = {FacebookComponent.class}, 
            


        
5条回答
  •  死守一世寂寞
    2021-01-04 10:10

    I found the answer here: https://stackoverflow.com/a/29619594/1016472

    At the end I created a AppComponent with the right scope and let FacebookComponent and AnotherComponent extends this AppComponent.

    FacebookComponent and AnotherComponent does not have it's own scope (I removed it).

    Looks now like this:

    @AppScope
    @Component
    public interface AppComponent {
    
    }
    
    
    @Component(modules = {FacebookModule.class})
    public interface FacebookComponent extends AppComponent {
    
    }
    
    
    @Component(modules = {AnotherModule.class})
    public interface AnotherComponent extends AppComponent {
    
    }
    
    
    @FragmentScope
    @Component(dependencies = {FacebookComponent.class, AnotherComponent.class}, 
               modules = {FragmentFacebookLoginModule.class})
    public interface FragmentFacebookLoginComponent {
    
        void inject(FragmentFacebookLogin fragment);
    }
    

提交回复
热议问题