Dagger 2 - modules added to graph per activity vs in application.java

268 views Asked by At

Is it wise to to add modules to the Object graph in application.java file ? or should they only be added per activity?

For example, in an activity class imagine we already had a vehicle module but it was not added to the object graph. We then c could do the following in onCreate:

VehicleComponent vehicleComponent = DaggerVehicleComponent.builder().vehicleModule(new VehicleModule()).build();

this would then add the vehicle module to the graph and then we could use the @inject annotation on a variable called vehicle for example.

this is in contrast to doing the same call in the application.java file. Isn't the former better on memory ?

0

There are 0 answers