我是使用Android Dagger2,但是遇到了以下错误:
我的Module类:
@Module
public class ApplicationModule {
private final App mApp;
public ApplicationModule(App app) {
this.mApp = app;
}
@Provides
@Singleton
@ContextType("Application")
App provideApplicationContext(){
return mApp;
}
@Provides
@Singleton
P2PService provideP2PService(App context){
return new P2PService(context);
}
}
我的组件类:
@Singleton
@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
@ContextType("Application")
App getContext();
P2PService p2pService();
}
编译后,错误信息:
Error:(21, 16) error: com.sen5.smartlifebox.App cannot be provided without an @Inject constructor or from an @Provides-annotated method.
com.sen5.smartlifebox.App is injected at
com.sen5.smartlifebox.di.module.ApplicationModule.provideP2PService(context)
com.sen5.smartlifebox.data.p2p.P2PService is provided at
com.sen5.smartlifebox.di.component.ApplicationComponent.p2pService()
非常感谢您的建议!
@ContextType("Application")
是什么? - Raghunandan