This presentation is an update on Dagger 2. First, we'll give updates on our improvements to the implementation and the features that have been added since our original release. Then we'll discuss some of our plans for some new features and APIs that are coming in the next few months that should make dependency injection in Android applications easier and more straightforward than ever before.
23. Confidential + Proprietary
Error messages
error: coffee.Pump cannot be provided without an
@Provides-annotated method.
CoffeeMaker maker();
^
coffee.Pump is injected at
coffee.CoffeeMaker.<init>(…, pump)
coffee.CoffeeMaker is provided at
coffee.CoffeeApp.CoffeeComponent.maker()
25. Confidential + Proprietary
Development within Google
● Millions of test targets are executed for
every Dagger change
● Constant performance testing and
monitoring from JVM and Android projects
● New APIs are developed against a huge,
searchable repository of real usages
● It is an invaluable, proven model from which
we have gotten projects like Guava
Working with GitHub
● We haven't done as well as we need to
○ Google builds from HEAD, but the rest of the
world doesn't
○ Syncs from Google were big, unmanaged
dumps of changes with no compatibility
guarantees
● New release policy makes sure that there is
a versioned release about every 2 weeks
○ Cultivated change log
○ Compatibility guarantees
Project management
35. Confidential + ProprietaryConfidential + Proprietary
Considerations
Mobile devices mean we need to be judicious
● Number of allocations
● Long-term memory footprint
36. Confidential + ProprietaryConfidential + Proprietary
Unscoped
A new instance for every injection site
● Number of allocations
● Long-term memory footprint
38. Confidential + ProprietaryConfidential + Proprietary
● Number of allocations
● Long-term memory footprint
@Reusable
Instances can be reused, but how and when isn't
a functional requirement
39. Confidential + ProprietaryConfidential + Proprietary
Pressure-sensitive scopes
There should only be one instance, but if there is
memory pressure make it eligible for garbage
collection
● Number of allocations
● Long-term memory footprint
43. Confidential + Proprietary
What if we didn't have to have that method?
public final class MyAppication extends Application {
@Inject
MainActivitySubcomponent.Builder builder;
/* … */
}