What are the advantages of Dagger 2 over Dagger 1?
So far I found (just) 2:
In the same time I found one big disadvantage: you cannot have module overrides (@Module(overrides = true)
) in Dagger 2, which is largely annoying at least for me - it was very useful for unit test.
Are there other advantages / disadvantages?
Some advantages and disadvantages taken from https://blog.gouline.net/2015/05/04/dagger-2-even-sharper-less-square/ and http://google.github.io/dagger/dagger-1-migration.html:
Advantages of Dagger 2:
@Singleton
.And disadvantages:
inject()
method now has a strong type association with the injection target. This is good for debugging, but it complicates a common practice of injecting from base classes (e.g. base activities, fragments etc).overrides
. Modules that override for simple testing fakes can create a subclass of the module to emulate that behavior. Modules that use overrides and rely on dependency injection should be decomposed so that the overriden modules are instead represented as a choice between two modules.EDIT 2016/11/16: This is not a technical advantage, but Dagger 1 is now deprecated (as of September 15, 2016) and will no longer be actively developed. They recommend migrating to Dagger 2.