SlideShare una empresa de Scribd logo
1 de 47
Descargar para leer sin conexión
Confidential + ProprietaryConfidential + Proprietary
Dagger 2
Now Even Pointier!™
Confidential + ProprietaryConfidential + Proprietary
An introduction
Confidential + Proprietary
A quick (re)introduction to dependency injection
/* With Manual DI */
class CoffeeMaker {
private final Heater heater;
private final Pump pump;
CoffeeMaker(Heater heater, Pump pump) {
this.heater = checkNotNull(heater);
this.pump = checkNotNull(pump);
}
Coffee makeCoffee() {/* … */}
}
class CoffeeMain {
public static void main(String[] args) {
Heater heater = new ElectricHeater();
Pump pump = new Thermosiphon(heater);
Coffee coffee =
new CoffeeMaker(heater, pump).makeCoffee();
}
}
/* Without DI */
class CoffeeMaker {
private final Heater heater;
private final Pump pump;
CoffeeMaker() {
this.heater = new ElectricHeater();
this.pump = new Thermosiphon(heater);
}
Coffee makeCoffee() {/* … */}
}
class CoffeeMain {
public static void main(String[] args) {
Coffee coffee =
new CoffeeMaker().makeCoffee();
}
}
Confidential + Proprietary
DI with Dagger 2
Confidential + Proprietary
Dagger 2 - Injected objects
@Inject
Thermosiphon(Heater heater) {
this.heater = heater;
}
Confidential + Proprietary
Dagger 2 - declarative configuration
@Provides
@Singleton
Heater provideHeater() {
return new ElectricHeater();
}
Confidential + Proprietary
Dagger 2 - typesafe dependency injection
@Singleton
@Component(
modules = DripCoffeeModule.class)
public interface CoffeeComponent {
CoffeeMaker maker();
}
Confidential + Proprietary
OK, but why?
Confidential + Proprietary
Consistent, efficient
instance management
Confidential + Proprietary
Dagger 2.0.1 - 2.4
Confidential + ProprietaryConfidential + Proprietary
static @Provides
methods
Confidential + Proprietary
@Provides
Heater provideHeater() {
return new ElectricHeater();
}
Confidential + Proprietary
@Provides
static Heater provideHeater() {
return new ElectricHeater();
}
Confidential + ProprietaryConfidential + Proprietary
Subcomponents
Confidential + Proprietary
Subcomponents
@Component(modules = {ServerModule.class, AuthModule.class})
interface ServerComponent {
Server server();
SessionComponent sessionComponent(SessionModule sessionModule);
}
@Subcomponent(modules = SessionModule.class)
interface SessionComponent {
SessionInfo sessionInfo();
RequestComponent requestComponent();
}
@Subcomponent(modules = {RequestModule.class, AuthModule.class})
interface RequestComponent {
RequestHandler requestHandler();
}
Confidential + ProprietaryConfidential + Proprietary
Map Multibindings
Confidential + Proprietary
Map multibindings
Confidential + Proprietary
enum MessageType {
TEXT,
PHOTO,
LOCATION,
}
@MapKey
@interface ForMessageType {
MessageType value();
}
Map multibindings
@Provides
@IntoMap
@ForMessageType(TEXT)
Renderer contributeTextRenderer() { /*…*/ }
@Provides
@IntoMap
@ForMessageType(PHOTO)
Renderer contributePhotoRenderer() { /*…*/ }
@Provides
@IntoMap
@ForMessageType(LOCATION)
Renderer contributeVideoRenderer() { /*…*/ }
Confidential + Proprietary
Map multibindings
@Inject Map<MessageType, Provider<Renderer>> renderers;
// …
for (Message message : messages) {
renderers.get(message.type()).get().render(message);
}
Confidential + ProprietaryConfidential + Proprietary
Producers
Confidential + Proprietary
Producers
@ProducerModule(includes = UserModule.class)
final class UserResponseModule {
@Produces
static ListenableFuture<UserData>
lookUpUserData(
User user, UserDataStub stub) {
return stub.lookUpData(user);
}
@Produces
static Html renderHtml(
UserData data,
UserHtmlTemplate template) {
return template.render(data);
}
}
@Module
final class ExecutorModule {
@Provides
@Production
static Executor executor() {
return Executors.newCachedThreadPool();
}
}
@ProductionComponent(modules =
UserResponseModule.class)
interface UserResponseComponent {
ListenableFuture<Html> html();
}
Confidential + ProprietaryConfidential + Proprietary
Improved error
messages
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()
Confidential + ProprietaryConfidential + Proprietary
Project
Management
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
Confidential + Proprietary
Dagger 2.5+
Confidential + ProprietaryConfidential + Proprietary
Performance
enhancements
Confidential + Proprietary
The generated code
Confidential + Proprietary
Unnecessary Providers
Confidential + Proprietary
Retained references
Confidential + ProprietaryConfidential + Proprietary
@Binds
Confidential + Proprietary
@Provides
static Pump providePump(Thermosiphon pump) {
return pump;
}
Confidential + Proprietary
@Binds
abstract Pump bindPump(Thermosiphon pump);
Confidential + ProprietaryConfidential + Proprietary
Memory
management tools
Confidential + ProprietaryConfidential + Proprietary
Considerations
Mobile devices mean we need to be judicious
● Number of allocations
● Long-term memory footprint
Confidential + ProprietaryConfidential + Proprietary
Unscoped
A new instance for every injection site
● Number of allocations
● Long-term memory footprint
Confidential + ProprietaryConfidential + Proprietary
@Scope
Only one instance per component
● Number of allocations
● Long-term memory footprint
Confidential + ProprietaryConfidential + Proprietary
● Number of allocations
● Long-term memory footprint
@Reusable
Instances can be reused, but how and when isn't
a functional requirement
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
Confidential + ProprietaryConfidential + Proprietary
Easier
subcomponents
Confidential + Proprietary
An Application component
@Singleton
@Component(modules = ApplicationModule.class)
interface MyApplicationComponent {
MyApplication inject(MyApplication application);
@Component.Builder
interface Builder {
Builder applicationModule(ApplicationModule module);
MyApplicationComponent build();
}
}
Confidential + Proprietary
@ActivityScoped
@Subcomponent(
modules = ActivityModule.class)
interface MainActivitySubcomponent {
MainActivity injectMainActivity(
MainActivity activity);
@Subcomponent.Builder
interface Builder {
Builder activityModule(
ActivityModule activityModule);
MainActivitySubcomponent build();
}
}
An activity subcomponent today
@Singleton
@Component(modules = ApplicationModule.
class)
interface MyApplicationComponent {
MyApplication inject(
MyApplication application);
MainActivitySubcomponent.Builder
newMainActivitySubcomponentBuilder();
/* … */
}
Confidential + Proprietary
What if we didn't have to have that method?
public final class MyAppication extends Application {
@Inject
MainActivitySubcomponent.Builder builder;
/* … */
}
Confidential + Proprietary
First, a common interface
interface ActivityComponentBuilder<A extends Activity> {
ActivityComponentBuilder<A> activityModule(ActivityModule activityModule);
MembersInjector<A> build();
}
@ActivityScoped
@Subcomponent(modules = ActivityModule.class)
interface MainActivitySubcomponent {
MainActivity injectMainActivity(MainActivity activity);
@Subcomponent.Builder
interface Builder extends ActivityComponentBuilder<ActivityModule> {}
}
Confidential + Proprietary
Second, map multibinder
@Module
abstract class MainActivitySubcomponentModule {
@Binds @IntoMap @ActivityKey(MainActivity.class)
abstract ActivityComponentBuilder<?> bindBuilder(
MainActivitySubcomponent.Builder<MainActivity> impl);
}
Confidential + Proprietary
Finally, back to MyApplication
interface HasActivitySubcomponentBuilders {
<A extends Activity> ActivityComponentBuilder<A> getActivityComponentBuilder(
Class<? extends Activity> activityClass);
}
class MyApplication extends Application implements HasActivitySubcomponentBuilders {
@Inject Map<Class<? extends Activity, ActivityComponentBuilder<?>> activityComponentBuilders;
@Override
public <A extends Activity> ActivityComponentBuilder<A> getActivityComponentBuilder(
Class<? extends Activity> activityClass) {
checkArgument(activityComponentBuilders.containsKey(activityClass));
return (ActivityComponentBuilder<A>) activityComponentBuilders.get(activityClass);
}
}
Confidential + Proprietary
Q & A

Más contenido relacionado

La actualidad más candente

Architecture Components
Architecture Components Architecture Components
Architecture Components DataArt
 
Android training day 4
Android training day 4Android training day 4
Android training day 4Vivek Bhusal
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksWO Community
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationsourabh aggarwal
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideVisual Engineering
 
How To Utilize Context API With Class And Functional Componen in React.pptx
How To Utilize Context API With Class And Functional Componen in React.pptxHow To Utilize Context API With Class And Functional Componen in React.pptx
How To Utilize Context API With Class And Functional Componen in React.pptxBOSC Tech Labs
 

La actualidad más candente (16)

Day 5
Day 5Day 5
Day 5
 
Tech talk
Tech talkTech talk
Tech talk
 
Learn Drupal 8 Render Pipeline
Learn Drupal 8 Render PipelineLearn Drupal 8 Render Pipeline
Learn Drupal 8 Render Pipeline
 
9 services
9 services9 services
9 services
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 
Di code steps
Di code stepsDi code steps
Di code steps
 
Android training day 4
Android training day 4Android training day 4
Android training day 4
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
 
Concurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background TasksConcurrency and Thread-Safe Data Processing in Background Tasks
Concurrency and Thread-Safe Data Processing in Background Tasks
 
OSGi Puzzlers
OSGi PuzzlersOSGi Puzzlers
OSGi Puzzlers
 
Day 6
Day 6Day 6
Day 6
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentation
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
How To Utilize Context API With Class And Functional Componen in React.pptx
How To Utilize Context API With Class And Functional Componen in React.pptxHow To Utilize Context API With Class And Functional Componen in React.pptx
How To Utilize Context API With Class And Functional Componen in React.pptx
 

Destacado

PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...
PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...
PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...PROIDEA
 
[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub Szczepanik
[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub Szczepanik[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub Szczepanik
[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub SzczepanikPROIDEA
 
MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...
MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...
MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...PROIDEA
 
PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...
PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...
PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...PROIDEA
 
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...PROIDEA
 
PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...
PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...
PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...PROIDEA
 
PLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open Networking
PLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open NetworkingPLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open Networking
PLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open NetworkingPROIDEA
 
Atmosphere 2016 - Pawel Mastalerz, Wojciech Inglot - New way of building inf...
Atmosphere 2016 -  Pawel Mastalerz, Wojciech Inglot - New way of building inf...Atmosphere 2016 -  Pawel Mastalerz, Wojciech Inglot - New way of building inf...
Atmosphere 2016 - Pawel Mastalerz, Wojciech Inglot - New way of building inf...PROIDEA
 
MCE^3 - Ágnes Vásárhelyi - ReactiveCocoa Reloaded
MCE^3 - Ágnes Vásárhelyi - ReactiveCocoa ReloadedMCE^3 - Ágnes Vásárhelyi - ReactiveCocoa Reloaded
MCE^3 - Ágnes Vásárhelyi - ReactiveCocoa ReloadedPROIDEA
 
4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQ
4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQ4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQ
4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQPROIDEA
 
infraxstructure: Adam Kmin i Łukasz Bederski "Optymalizacja systemu chłodzen...
infraxstructure: Adam Kmin i Łukasz Bederski  "Optymalizacja systemu chłodzen...infraxstructure: Adam Kmin i Łukasz Bederski  "Optymalizacja systemu chłodzen...
infraxstructure: Adam Kmin i Łukasz Bederski "Optymalizacja systemu chłodzen...PROIDEA
 
[4developers] - Codzienność z Legacy Code (Tomek Gramza)
[4developers] - Codzienność z Legacy Code (Tomek Gramza)[4developers] - Codzienność z Legacy Code (Tomek Gramza)
[4developers] - Codzienność z Legacy Code (Tomek Gramza)PROIDEA
 
PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...
PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...
PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...PROIDEA
 
PLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment Routing
PLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment RoutingPLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment Routing
PLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment RoutingPROIDEA
 
DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System
DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System
DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System PROIDEA
 
JDD 2016 - Tomasz Ducin - Backend-less Development Revisited
JDD 2016 - Tomasz Ducin - Backend-less Development RevisitedJDD 2016 - Tomasz Ducin - Backend-less Development Revisited
JDD 2016 - Tomasz Ducin - Backend-less Development RevisitedPROIDEA
 
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsJDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsPROIDEA
 
JDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And Others
JDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And OthersJDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And Others
JDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And OthersPROIDEA
 

Destacado (18)

PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...
PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...
PLNOG 17 - Maciej Flak - Cisco Cloud Networking - czyli kompletna infrastrukt...
 
[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub Szczepanik
[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub Szczepanik[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub Szczepanik
[4developers] - Droga Scrum Mastera do Agile Coacha (Jakub Szczepanik
 
MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...
MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...
MCE^3 - C. Todd Lombardo - Design Sprints: No, Design Doesn't Go Faster, You ...
 
PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...
PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...
PLNOG 17 - Grzegorz Wenc - Na co zwracać uwagę przy wyborze podstawowych urzą...
 
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
[CONFidence 2016] Sławomir Kosowski - Introduction to iOS Application Securit...
 
PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...
PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...
PLNOG 17 - Shabbir Ahmad - Dell Open Networking i Big Monitoring Fabric: unik...
 
PLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open Networking
PLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open NetworkingPLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open Networking
PLNOG 17 - Shabbir Ahmad - Dell EMC’s SDN strategy based on Open Networking
 
Atmosphere 2016 - Pawel Mastalerz, Wojciech Inglot - New way of building inf...
Atmosphere 2016 -  Pawel Mastalerz, Wojciech Inglot - New way of building inf...Atmosphere 2016 -  Pawel Mastalerz, Wojciech Inglot - New way of building inf...
Atmosphere 2016 - Pawel Mastalerz, Wojciech Inglot - New way of building inf...
 
MCE^3 - Ágnes Vásárhelyi - ReactiveCocoa Reloaded
MCE^3 - Ágnes Vásárhelyi - ReactiveCocoa ReloadedMCE^3 - Ágnes Vásárhelyi - ReactiveCocoa Reloaded
MCE^3 - Ágnes Vásárhelyi - ReactiveCocoa Reloaded
 
4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQ
4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQ4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQ
4Developers: Łukasz Łysik- Message-driven architecture with RabbitMQ
 
infraxstructure: Adam Kmin i Łukasz Bederski "Optymalizacja systemu chłodzen...
infraxstructure: Adam Kmin i Łukasz Bederski  "Optymalizacja systemu chłodzen...infraxstructure: Adam Kmin i Łukasz Bederski  "Optymalizacja systemu chłodzen...
infraxstructure: Adam Kmin i Łukasz Bederski "Optymalizacja systemu chłodzen...
 
[4developers] - Codzienność z Legacy Code (Tomek Gramza)
[4developers] - Codzienność z Legacy Code (Tomek Gramza)[4developers] - Codzienność z Legacy Code (Tomek Gramza)
[4developers] - Codzienność z Legacy Code (Tomek Gramza)
 
PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...
PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...
PLNOG 17 - Dominik Bocheński, Łukasz Walicki - Zapomnij o VPS - nadeszła era ...
 
PLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment Routing
PLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment RoutingPLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment Routing
PLNOG 17 - Leonir Hoxha - Next Generation Network Architecture - Segment Routing
 
DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System
DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System
DOD 2016 - Sabina Staszczyk - How We Phased out Motivational System
 
JDD 2016 - Tomasz Ducin - Backend-less Development Revisited
JDD 2016 - Tomasz Ducin - Backend-less Development RevisitedJDD 2016 - Tomasz Ducin - Backend-less Development Revisited
JDD 2016 - Tomasz Ducin - Backend-less Development Revisited
 
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsJDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
 
JDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And Others
JDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And OthersJDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And Others
JDD 2016 - Michal Gruca - Continous Improvement, Developing Yourself And Others
 

Similar a MCE^3 - Gregory Kick - Dagger 2

Dependency injection using dagger2
Dependency injection using dagger2Dependency injection using dagger2
Dependency injection using dagger2Javad Hashemi
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightMichael Pustovit
 
Dagger 2. Right way to do Dependency Injection
Dagger 2. Right way to do Dependency InjectionDagger 2. Right way to do Dependency Injection
Dagger 2. Right way to do Dependency InjectionStfalcon Meetups
 
Антон Минашкин "Dagger 2. Right way to do Dependency Injections"
Антон Минашкин "Dagger 2. Right way to do Dependency Injections"Антон Минашкин "Dagger 2. Right way to do Dependency Injections"
Антон Минашкин "Dagger 2. Right way to do Dependency Injections"Fwdays
 
Dagger 2. The Right Way to Dependency Injections
Dagger 2. The Right Way to Dependency InjectionsDagger 2. The Right Way to Dependency Injections
Dagger 2. The Right Way to Dependency InjectionsGlobalLogic Ukraine
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT TalkConstantine Mars
 
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Yoshifumi Kawai
 
Commenting in Agile Development
Commenting in Agile DevelopmentCommenting in Agile Development
Commenting in Agile DevelopmentJan Rybák Benetka
 
Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02rhemsolutions
 
Writing Ansible Modules (DENOG11)
Writing Ansible Modules (DENOG11)Writing Ansible Modules (DENOG11)
Writing Ansible Modules (DENOG11)Martin Schütte
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinNida Ismail Shah
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzgKristijan Jurković
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConos890
 
Using and contributing to the next Guice
Using and contributing to the next GuiceUsing and contributing to the next Guice
Using and contributing to the next GuiceAdrian Cole
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedGil Fink
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFPierre-Yves Ricau
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedGil Fink
 

Similar a MCE^3 - Gregory Kick - Dagger 2 (20)

Dependency injection using dagger2
Dependency injection using dagger2Dependency injection using dagger2
Dependency injection using dagger2
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 
Dagger 2. Right way to do Dependency Injection
Dagger 2. Right way to do Dependency InjectionDagger 2. Right way to do Dependency Injection
Dagger 2. Right way to do Dependency Injection
 
Антон Минашкин "Dagger 2. Right way to do Dependency Injections"
Антон Минашкин "Dagger 2. Right way to do Dependency Injections"Антон Минашкин "Dagger 2. Right way to do Dependency Injections"
Антон Минашкин "Dagger 2. Right way to do Dependency Injections"
 
Dagger 2. The Right Way to Dependency Injections
Dagger 2. The Right Way to Dependency InjectionsDagger 2. The Right Way to Dependency Injections
Dagger 2. The Right Way to Dependency Injections
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT Talk
 
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer ...
 
Android TDD
Android TDDAndroid TDD
Android TDD
 
Commenting in Agile Development
Commenting in Agile DevelopmentCommenting in Agile Development
Commenting in Agile Development
 
Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02Architecting your GWT applications with GWT-Platform - Lesson 02
Architecting your GWT applications with GWT-Platform - Lesson 02
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
Writing Ansible Modules (DENOG11)
Writing Ansible Modules (DENOG11)Writing Ansible Modules (DENOG11)
Writing Ansible Modules (DENOG11)
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
Building maintainable app #droidconzg
Building maintainable app #droidconzgBuilding maintainable app #droidconzg
Building maintainable app #droidconzg
 
Devoxx 2012 (v2)
Devoxx 2012 (v2)Devoxx 2012 (v2)
Devoxx 2012 (v2)
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
 
Using and contributing to the next Guice
Using and contributing to the next GuiceUsing and contributing to the next Guice
Using and contributing to the next Guice
 
Stencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has ArrivedStencil: The Time for Vanilla Web Components has Arrived
Stencil: The Time for Vanilla Web Components has Arrived
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Stencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrivedStencil the time for vanilla web components has arrived
Stencil the time for vanilla web components has arrived
 

Último

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

MCE^3 - Gregory Kick - Dagger 2

  • 1. Confidential + ProprietaryConfidential + Proprietary Dagger 2 Now Even Pointier!™
  • 2. Confidential + ProprietaryConfidential + Proprietary An introduction
  • 3. Confidential + Proprietary A quick (re)introduction to dependency injection /* With Manual DI */ class CoffeeMaker { private final Heater heater; private final Pump pump; CoffeeMaker(Heater heater, Pump pump) { this.heater = checkNotNull(heater); this.pump = checkNotNull(pump); } Coffee makeCoffee() {/* … */} } class CoffeeMain { public static void main(String[] args) { Heater heater = new ElectricHeater(); Pump pump = new Thermosiphon(heater); Coffee coffee = new CoffeeMaker(heater, pump).makeCoffee(); } } /* Without DI */ class CoffeeMaker { private final Heater heater; private final Pump pump; CoffeeMaker() { this.heater = new ElectricHeater(); this.pump = new Thermosiphon(heater); } Coffee makeCoffee() {/* … */} } class CoffeeMain { public static void main(String[] args) { Coffee coffee = new CoffeeMaker().makeCoffee(); } }
  • 5. Confidential + Proprietary Dagger 2 - Injected objects @Inject Thermosiphon(Heater heater) { this.heater = heater; }
  • 6. Confidential + Proprietary Dagger 2 - declarative configuration @Provides @Singleton Heater provideHeater() { return new ElectricHeater(); }
  • 7. Confidential + Proprietary Dagger 2 - typesafe dependency injection @Singleton @Component( modules = DripCoffeeModule.class) public interface CoffeeComponent { CoffeeMaker maker(); }
  • 9. Confidential + Proprietary Consistent, efficient instance management
  • 11. Confidential + ProprietaryConfidential + Proprietary static @Provides methods
  • 12. Confidential + Proprietary @Provides Heater provideHeater() { return new ElectricHeater(); }
  • 13. Confidential + Proprietary @Provides static Heater provideHeater() { return new ElectricHeater(); }
  • 14. Confidential + ProprietaryConfidential + Proprietary Subcomponents
  • 15. Confidential + Proprietary Subcomponents @Component(modules = {ServerModule.class, AuthModule.class}) interface ServerComponent { Server server(); SessionComponent sessionComponent(SessionModule sessionModule); } @Subcomponent(modules = SessionModule.class) interface SessionComponent { SessionInfo sessionInfo(); RequestComponent requestComponent(); } @Subcomponent(modules = {RequestModule.class, AuthModule.class}) interface RequestComponent { RequestHandler requestHandler(); }
  • 16. Confidential + ProprietaryConfidential + Proprietary Map Multibindings
  • 18. Confidential + Proprietary enum MessageType { TEXT, PHOTO, LOCATION, } @MapKey @interface ForMessageType { MessageType value(); } Map multibindings @Provides @IntoMap @ForMessageType(TEXT) Renderer contributeTextRenderer() { /*…*/ } @Provides @IntoMap @ForMessageType(PHOTO) Renderer contributePhotoRenderer() { /*…*/ } @Provides @IntoMap @ForMessageType(LOCATION) Renderer contributeVideoRenderer() { /*…*/ }
  • 19. Confidential + Proprietary Map multibindings @Inject Map<MessageType, Provider<Renderer>> renderers; // … for (Message message : messages) { renderers.get(message.type()).get().render(message); }
  • 20. Confidential + ProprietaryConfidential + Proprietary Producers
  • 21. Confidential + Proprietary Producers @ProducerModule(includes = UserModule.class) final class UserResponseModule { @Produces static ListenableFuture<UserData> lookUpUserData( User user, UserDataStub stub) { return stub.lookUpData(user); } @Produces static Html renderHtml( UserData data, UserHtmlTemplate template) { return template.render(data); } } @Module final class ExecutorModule { @Provides @Production static Executor executor() { return Executors.newCachedThreadPool(); } } @ProductionComponent(modules = UserResponseModule.class) interface UserResponseComponent { ListenableFuture<Html> html(); }
  • 22. Confidential + ProprietaryConfidential + Proprietary Improved error messages
  • 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()
  • 24. Confidential + ProprietaryConfidential + Proprietary Project Management
  • 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
  • 27. Confidential + ProprietaryConfidential + Proprietary Performance enhancements
  • 32. Confidential + Proprietary @Provides static Pump providePump(Thermosiphon pump) { return pump; }
  • 33. Confidential + Proprietary @Binds abstract Pump bindPump(Thermosiphon pump);
  • 34. Confidential + ProprietaryConfidential + Proprietary Memory management tools
  • 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
  • 37. Confidential + ProprietaryConfidential + Proprietary @Scope Only one instance per component ● 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
  • 40. Confidential + ProprietaryConfidential + Proprietary Easier subcomponents
  • 41. Confidential + Proprietary An Application component @Singleton @Component(modules = ApplicationModule.class) interface MyApplicationComponent { MyApplication inject(MyApplication application); @Component.Builder interface Builder { Builder applicationModule(ApplicationModule module); MyApplicationComponent build(); } }
  • 42. Confidential + Proprietary @ActivityScoped @Subcomponent( modules = ActivityModule.class) interface MainActivitySubcomponent { MainActivity injectMainActivity( MainActivity activity); @Subcomponent.Builder interface Builder { Builder activityModule( ActivityModule activityModule); MainActivitySubcomponent build(); } } An activity subcomponent today @Singleton @Component(modules = ApplicationModule. class) interface MyApplicationComponent { MyApplication inject( MyApplication application); MainActivitySubcomponent.Builder newMainActivitySubcomponentBuilder(); /* … */ }
  • 43. Confidential + Proprietary What if we didn't have to have that method? public final class MyAppication extends Application { @Inject MainActivitySubcomponent.Builder builder; /* … */ }
  • 44. Confidential + Proprietary First, a common interface interface ActivityComponentBuilder<A extends Activity> { ActivityComponentBuilder<A> activityModule(ActivityModule activityModule); MembersInjector<A> build(); } @ActivityScoped @Subcomponent(modules = ActivityModule.class) interface MainActivitySubcomponent { MainActivity injectMainActivity(MainActivity activity); @Subcomponent.Builder interface Builder extends ActivityComponentBuilder<ActivityModule> {} }
  • 45. Confidential + Proprietary Second, map multibinder @Module abstract class MainActivitySubcomponentModule { @Binds @IntoMap @ActivityKey(MainActivity.class) abstract ActivityComponentBuilder<?> bindBuilder( MainActivitySubcomponent.Builder<MainActivity> impl); }
  • 46. Confidential + Proprietary Finally, back to MyApplication interface HasActivitySubcomponentBuilders { <A extends Activity> ActivityComponentBuilder<A> getActivityComponentBuilder( Class<? extends Activity> activityClass); } class MyApplication extends Application implements HasActivitySubcomponentBuilders { @Inject Map<Class<? extends Activity, ActivityComponentBuilder<?>> activityComponentBuilders; @Override public <A extends Activity> ActivityComponentBuilder<A> getActivityComponentBuilder( Class<? extends Activity> activityClass) { checkArgument(activityComponentBuilders.containsKey(activityClass)); return (ActivityComponentBuilder<A>) activityComponentBuilders.get(activityClass); } }