android - Java dependency injection: Dagger 1 vs Dagger 2, which is better? -
what advantages of dagger 2 on dagger 1?
so far found (just) 2:
- dagger 2 allows use code obfuscation proguard
- dagger 2 faster (which not of advantage when using android application sure important thing if use kind of server)
in same time found 1 big disadvantage: cannot have module overrides (@module(overrides = true)
) in dagger 2, largely annoying @ least me - useful unit test.
are there other advantages / disadvantages?
some advantages , disadvantages taken https://blog.gouline.net/2015/05/04/dagger-2-even-sharper-less-square/ , http://google.github.io/dagger/dagger-1-migration.html:
advantages of dagger 2:
- no more reflection - done concrete calls (proguard works no configuration @ all)
- no more runtime graph composition - improves performance, including per-request cases
- traceable - better generated code , no reflection make code readable , easy follow
- supports method injection in addition field , constructor injection 2 types supported dagger 1
- modules require less configuration dagger 1
- allows users use well-formed scope annotation. dagger 1 supported single scope:
@singleton
.
and disadvantages:
- the
inject()
method has strong type association injection target. debugging, complicates common practice of injecting base classes (e.g. base activities, fragments etc). - component implementation requires rebuilding project appear , injection-related compile errors result in class disappearing (i.e. not being generated).
- doesn't support
overrides
. modules override simple testing fakes can create subclass of module emulate behavior. modules use overrides , rely on dependency injection should decomposed overriden modules instead represented choice between 2 modules.
edit 2016/11/16: not technical advantage, dagger 1 deprecated (as of september 15, 2016) , no longer actively developed. recommend migrating dagger 2.
Comments
Post a Comment