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 (eg 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.
I wouldn't recommend having a look at toothpick .
As a co-author, I am obviously over biased, but yeah this one is far simpler to use, at least as fast in most cases than the daggers. And really the scope tree is a very very powerful way to develop more advanced features like recycling instances in scopes spanning on multiple activities.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.