java - Dagger 2: avoid exporting private dependencies -


lets have module want export instance of a. a requires instances of band c passed in constructor. declare them in module:

public class samplemodule {      @provides     @singleton     providea(b b, c c){         return new a(b, c);     }      @provides     @singleton     b provideb(){         return new b();     }      @provides     @singleton     c providec(){         return new c();      } } 

this works, b , c available elsewhere in code. want keep them private , force client classes have access a.

is there way achieve this?

the easiest way accomplish goal bind types don't want made available (in case b , c) @qualifier not accessible.

then, while b , c might be accessible outside module, in order inject them need supply qualifier, not.

@module public final class samplemodule {   @qualifier   @retention(runtime)   private @interface samplemoduleonly {}    @provides   @singleton   static providea(@samplemoduleonly b b, @samplemoduleonly c c){     return new a(b, c);   }    @provides   @samplemoduleonly    @singleton   static b provideb(){     return new b();   }    @provides   @samplemoduleonly    @singleton   static c providec(){     return new c();    } } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -