error: [Dagger/MissingBinding] when trying building the project
I have a service class and I want to provide it via Dagger. But I get this error below:
error: [Dagger/MissingBinding] service.KeyStoreService cannot be
provided without an @Inject constructor or an @Provides-annotated
method. service.KeyStoreService is provided at
di.component.ApplicationComponent.getKeyStoreService()
Here is my component class:
@ApplicationScope
@Component(modules = {ApplicationContextModule.class, KeyStoreModule.class})
public interface ApplicationComponent {
@ApplicationContext
Context getApplicationContext();
KeyStoreService getKeyStoreService();
}
Here is my KeyStoreModule:
@Module(includes = {ApplicationContextModule.class})
public class KeyStoreModule {
@Provides
@ApplicationScope
KeyStoreServiceInterface getKeyStoreService(@ApplicationScope Context context){
File file = new File(context.getFilesDir(), "keystore/keystore");
return new KeyStoreService(file);
}
}
KeyStoreService implements KeyStoreServiceInterface.
Here is how I start Dagger2:
public class MyApplication extends Application {
private ApplicationComponent applicationComponent;
@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
}
}
Anyone see where it could have gone wrong? I looked at similar questions on Stackoverflow but did not find anything that helped me.
java
add a comment |
I have a service class and I want to provide it via Dagger. But I get this error below:
error: [Dagger/MissingBinding] service.KeyStoreService cannot be
provided without an @Inject constructor or an @Provides-annotated
method. service.KeyStoreService is provided at
di.component.ApplicationComponent.getKeyStoreService()
Here is my component class:
@ApplicationScope
@Component(modules = {ApplicationContextModule.class, KeyStoreModule.class})
public interface ApplicationComponent {
@ApplicationContext
Context getApplicationContext();
KeyStoreService getKeyStoreService();
}
Here is my KeyStoreModule:
@Module(includes = {ApplicationContextModule.class})
public class KeyStoreModule {
@Provides
@ApplicationScope
KeyStoreServiceInterface getKeyStoreService(@ApplicationScope Context context){
File file = new File(context.getFilesDir(), "keystore/keystore");
return new KeyStoreService(file);
}
}
KeyStoreService implements KeyStoreServiceInterface.
Here is how I start Dagger2:
public class MyApplication extends Application {
private ApplicationComponent applicationComponent;
@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
}
}
Anyone see where it could have gone wrong? I looked at similar questions on Stackoverflow but did not find anything that helped me.
java
add a comment |
I have a service class and I want to provide it via Dagger. But I get this error below:
error: [Dagger/MissingBinding] service.KeyStoreService cannot be
provided without an @Inject constructor or an @Provides-annotated
method. service.KeyStoreService is provided at
di.component.ApplicationComponent.getKeyStoreService()
Here is my component class:
@ApplicationScope
@Component(modules = {ApplicationContextModule.class, KeyStoreModule.class})
public interface ApplicationComponent {
@ApplicationContext
Context getApplicationContext();
KeyStoreService getKeyStoreService();
}
Here is my KeyStoreModule:
@Module(includes = {ApplicationContextModule.class})
public class KeyStoreModule {
@Provides
@ApplicationScope
KeyStoreServiceInterface getKeyStoreService(@ApplicationScope Context context){
File file = new File(context.getFilesDir(), "keystore/keystore");
return new KeyStoreService(file);
}
}
KeyStoreService implements KeyStoreServiceInterface.
Here is how I start Dagger2:
public class MyApplication extends Application {
private ApplicationComponent applicationComponent;
@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
}
}
Anyone see where it could have gone wrong? I looked at similar questions on Stackoverflow but did not find anything that helped me.
java
I have a service class and I want to provide it via Dagger. But I get this error below:
error: [Dagger/MissingBinding] service.KeyStoreService cannot be
provided without an @Inject constructor or an @Provides-annotated
method. service.KeyStoreService is provided at
di.component.ApplicationComponent.getKeyStoreService()
Here is my component class:
@ApplicationScope
@Component(modules = {ApplicationContextModule.class, KeyStoreModule.class})
public interface ApplicationComponent {
@ApplicationContext
Context getApplicationContext();
KeyStoreService getKeyStoreService();
}
Here is my KeyStoreModule:
@Module(includes = {ApplicationContextModule.class})
public class KeyStoreModule {
@Provides
@ApplicationScope
KeyStoreServiceInterface getKeyStoreService(@ApplicationScope Context context){
File file = new File(context.getFilesDir(), "keystore/keystore");
return new KeyStoreService(file);
}
}
KeyStoreService implements KeyStoreServiceInterface.
Here is how I start Dagger2:
public class MyApplication extends Application {
private ApplicationComponent applicationComponent;
@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
}
}
Anyone see where it could have gone wrong? I looked at similar questions on Stackoverflow but did not find anything that helped me.
java
java
edited Nov 20 '18 at 21:53
Carlton
asked Nov 20 '18 at 21:45
CarltonCarlton
93421436
93421436
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Here is a thing: Dagger provides instances based on specific type. Here are a couple of ways to deal with this problem
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServiceInterfacetoKeyStoreServiceinKeyStoreModule
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServicetoKeyStoreServiceInterfaceinApplicationComponent
- Create an abstract method with
@Bindsannotation which will receiveKeyStoreServiceand which return type will beKeyStoreServiceInterface(in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with@Bindsannotations or to makeKeyStoreModuleabstract and modifygetKeyStoreServicemethod to be static) - Again, using
@Bindsannotation to mapKeyStoreServiceinstance to the providedKeyStoreServiceInterface, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger - Not using
@Bindsannotation, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger
Thanks for the help and informative post!
– Carlton
Nov 20 '18 at 22:56
You are always welcome!
– Andrey Ilyunin
Nov 20 '18 at 22:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402053%2ferror-dagger-missingbinding-when-trying-building-the-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a thing: Dagger provides instances based on specific type. Here are a couple of ways to deal with this problem
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServiceInterfacetoKeyStoreServiceinKeyStoreModule
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServicetoKeyStoreServiceInterfaceinApplicationComponent
- Create an abstract method with
@Bindsannotation which will receiveKeyStoreServiceand which return type will beKeyStoreServiceInterface(in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with@Bindsannotations or to makeKeyStoreModuleabstract and modifygetKeyStoreServicemethod to be static) - Again, using
@Bindsannotation to mapKeyStoreServiceinstance to the providedKeyStoreServiceInterface, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger - Not using
@Bindsannotation, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger
Thanks for the help and informative post!
– Carlton
Nov 20 '18 at 22:56
You are always welcome!
– Andrey Ilyunin
Nov 20 '18 at 22:56
add a comment |
Here is a thing: Dagger provides instances based on specific type. Here are a couple of ways to deal with this problem
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServiceInterfacetoKeyStoreServiceinKeyStoreModule
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServicetoKeyStoreServiceInterfaceinApplicationComponent
- Create an abstract method with
@Bindsannotation which will receiveKeyStoreServiceand which return type will beKeyStoreServiceInterface(in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with@Bindsannotations or to makeKeyStoreModuleabstract and modifygetKeyStoreServicemethod to be static) - Again, using
@Bindsannotation to mapKeyStoreServiceinstance to the providedKeyStoreServiceInterface, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger - Not using
@Bindsannotation, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger
Thanks for the help and informative post!
– Carlton
Nov 20 '18 at 22:56
You are always welcome!
– Andrey Ilyunin
Nov 20 '18 at 22:56
add a comment |
Here is a thing: Dagger provides instances based on specific type. Here are a couple of ways to deal with this problem
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServiceInterfacetoKeyStoreServiceinKeyStoreModule
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServicetoKeyStoreServiceInterfaceinApplicationComponent
- Create an abstract method with
@Bindsannotation which will receiveKeyStoreServiceand which return type will beKeyStoreServiceInterface(in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with@Bindsannotations or to makeKeyStoreModuleabstract and modifygetKeyStoreServicemethod to be static) - Again, using
@Bindsannotation to mapKeyStoreServiceinstance to the providedKeyStoreServiceInterface, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger - Not using
@Bindsannotation, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger
Here is a thing: Dagger provides instances based on specific type. Here are a couple of ways to deal with this problem
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServiceInterfacetoKeyStoreServiceinKeyStoreModule
- Change the return type of
getKeyStoreServicemethod fromKeyStoreServicetoKeyStoreServiceInterfaceinApplicationComponent
- Create an abstract method with
@Bindsannotation which will receiveKeyStoreServiceand which return type will beKeyStoreServiceInterface(in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with@Bindsannotations or to makeKeyStoreModuleabstract and modifygetKeyStoreServicemethod to be static) - Again, using
@Bindsannotation to mapKeyStoreServiceinstance to the providedKeyStoreServiceInterface, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger - Not using
@Bindsannotation, but applying@Injectannotation onKeyStoreServiceconstructor and provide keystoreFilethrough Dagger
answered Nov 20 '18 at 22:05
Andrey IlyuninAndrey Ilyunin
1,318220
1,318220
Thanks for the help and informative post!
– Carlton
Nov 20 '18 at 22:56
You are always welcome!
– Andrey Ilyunin
Nov 20 '18 at 22:56
add a comment |
Thanks for the help and informative post!
– Carlton
Nov 20 '18 at 22:56
You are always welcome!
– Andrey Ilyunin
Nov 20 '18 at 22:56
Thanks for the help and informative post!
– Carlton
Nov 20 '18 at 22:56
Thanks for the help and informative post!
– Carlton
Nov 20 '18 at 22:56
You are always welcome!
– Andrey Ilyunin
Nov 20 '18 at 22:56
You are always welcome!
– Andrey Ilyunin
Nov 20 '18 at 22:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402053%2ferror-dagger-missingbinding-when-trying-building-the-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown