error: [Dagger/MissingBinding] when trying building the project












1















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.










share|improve this question





























    1















    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.










    share|improve this question



























      1












      1








      1








      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.










      share|improve this question
















      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 android dependency-injection dagger-2 dagger






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 '18 at 21:53







      Carlton

















      asked Nov 20 '18 at 21:45









      CarltonCarlton

      93421436




      93421436
























          1 Answer
          1






          active

          oldest

          votes


















          2














          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 getKeyStoreService method from KeyStoreServiceInterface to KeyStoreService in KeyStoreModule

          • Change the return type of getKeyStoreService method from KeyStoreService to KeyStoreServiceInterface in ApplicationComponent

          • Create an abstract method with @Binds annotation which will receive KeyStoreService and which return type will be KeyStoreServiceInterface (in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with @Binds annotations or to make KeyStoreModule abstract and modify getKeyStoreService method to be static)

          • Again, using @Binds annotation to map KeyStoreService instance to the provided KeyStoreServiceInterface, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger

          • Not using @Binds annotation, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger






          share|improve this answer
























          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          2














          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 getKeyStoreService method from KeyStoreServiceInterface to KeyStoreService in KeyStoreModule

          • Change the return type of getKeyStoreService method from KeyStoreService to KeyStoreServiceInterface in ApplicationComponent

          • Create an abstract method with @Binds annotation which will receive KeyStoreService and which return type will be KeyStoreServiceInterface (in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with @Binds annotations or to make KeyStoreModule abstract and modify getKeyStoreService method to be static)

          • Again, using @Binds annotation to map KeyStoreService instance to the provided KeyStoreServiceInterface, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger

          • Not using @Binds annotation, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger






          share|improve this answer
























          • 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
















          2














          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 getKeyStoreService method from KeyStoreServiceInterface to KeyStoreService in KeyStoreModule

          • Change the return type of getKeyStoreService method from KeyStoreService to KeyStoreServiceInterface in ApplicationComponent

          • Create an abstract method with @Binds annotation which will receive KeyStoreService and which return type will be KeyStoreServiceInterface (in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with @Binds annotations or to make KeyStoreModule abstract and modify getKeyStoreService method to be static)

          • Again, using @Binds annotation to map KeyStoreService instance to the provided KeyStoreServiceInterface, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger

          • Not using @Binds annotation, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger






          share|improve this answer
























          • 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














          2












          2








          2







          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 getKeyStoreService method from KeyStoreServiceInterface to KeyStoreService in KeyStoreModule

          • Change the return type of getKeyStoreService method from KeyStoreService to KeyStoreServiceInterface in ApplicationComponent

          • Create an abstract method with @Binds annotation which will receive KeyStoreService and which return type will be KeyStoreServiceInterface (in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with @Binds annotations or to make KeyStoreModule abstract and modify getKeyStoreService method to be static)

          • Again, using @Binds annotation to map KeyStoreService instance to the provided KeyStoreServiceInterface, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger

          • Not using @Binds annotation, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger






          share|improve this answer













          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 getKeyStoreService method from KeyStoreServiceInterface to KeyStoreService in KeyStoreModule

          • Change the return type of getKeyStoreService method from KeyStoreService to KeyStoreServiceInterface in ApplicationComponent

          • Create an abstract method with @Binds annotation which will receive KeyStoreService and which return type will be KeyStoreServiceInterface (in order to do this the whole module should be abstract - so it is possible to either create separate abstract module with @Binds annotations or to make KeyStoreModule abstract and modify getKeyStoreService method to be static)

          • Again, using @Binds annotation to map KeyStoreService instance to the provided KeyStoreServiceInterface, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger

          • Not using @Binds annotation, but applying @Inject annotation on KeyStoreService constructor and provide keystore File through Dagger







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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



















          • 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




















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()