dependency injection - Dagger Modules with constructor arguments? -


in guice, had full control on when modules constructed, , used modules constructor arguments installed.

in dagger however, method of referencing other modules through @module includes annotation, , doesn't present me same method of creating modules install.

is possible create sane objectgraph multiple modules have constructor arguments? 1 work dagger-compiler, , not run cyclical graph?

if have multiple modules use same object maybe should separate object own module. example, lot of modules use application context have following module:

@module public class contextmodule {      private final context mcontext;      public contextmodule(context context) {         mcontext = context;     }      @provides     public context providecontext() {         return mcontext;     }  } 

so in other modules when when need context object include module.

for example:

@module(entrypoints = { myfragment.class }, includes = { contextmodule.class }) public class servicesmodule {      @provides     public locationmanager providelocationmanager(context context) {          return (locationmanager) context.getsystemservice(context.location_service);     }      @provides     public geocoder providegeocoder(context context) {         return new geocoder(context);     } } 

then when construct object graph end 1 module takes application context argument.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -