Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagger2相关 #31

Closed
duchao opened this issue Dec 7, 2016 · 6 comments
Closed

Dagger2相关 #31

duchao opened this issue Dec 7, 2016 · 6 comments

Comments

@duchao
Copy link

duchao commented Dec 7, 2016

@ContextLife("Application")
App getContext(); // 提供App的Context

Activity getActivity();

@Provides
@ActivityScope
public Activity provideActivity() {
    return mActivity;
}

等等

这些代码没用到吧?
看的很是费解,尤其是ContextLife.java这个不是scope吧,自定义标记的话,文件名看起来好难懂

再提个小bug哈
设置->清除缓存 不能实时更新,清除一次,再浏览网页,产生的缓存就不能清除了

@codeestX
Copy link
Owner

codeestX commented Dec 7, 2016

@duchao Hello,这两个get方法的确没用到,在component中可以不写,ContextLife是一个dagger2的Qualifier注解,用来给同类型的构造器打Tag来区别的,目前暂时没有用到,也可以不标注的。这个bug我会去看下的,感谢反馈哈

@duchao duchao closed this as completed Dec 7, 2016
@caopeng000
Copy link


请问一下,你是怎么切换不同的HOST的,我现在有两个不同的HOST,我使用了和你类似的代码,好像一直只能初始化一个HOST,是不是我还要注意其他的东西。谢谢

@codeestX
Copy link
Owner

Hi @caopeng000 ,我为每个不同的HOST都创建了一个Retrofit,用Qualifier来区分这些Retrofit,可以看下这个类HttpModule

@caopeng000
Copy link

这个我知道。我也是这样写的。但是有且只能识别一个,还有其他原因吗

@codeestX
Copy link
Owner

@caopeng000 没有具体代码的话我只能猜原因了..比如依赖的提供方和接收方都要标注相同的Qualifier

@Singleton
    @Provides
    @VtexUrl
    Retrofit provideVtexRetrofit(Retrofit.Builder builder, OkHttpClient client) {
        return createRetrofit(builder, client, VtexApis.HOST);
    }
@Singleton
    @Provides
    VtexApis provideVtexService(@VtexUrl Retrofit retrofit) {
        return retrofit.create(VtexApis.class);
    }

或者看下Dagger2编译后生成的代码,从里面找原因

@caopeng000
Copy link

好了。谢谢。没匹配上。提供方写的都是同一个地址

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants