SlideShare a Scribd company logo
1 of 27
Download to read offline
Dependency Injection
       with
    RoboGuice



   ©2013 Tom Braun <tom.braun@apps4use.com>
{concept}
Inversion of Control (IoC)




      {concept}
Dependency Injection (DI)




Googe Guice                    Spring core   PicoContainer   Plexus




                  Android
RoboGuice                          Dagger
                 Annotations
Dependency Injection (DI)

Makes code ...
● more concise


● more modular


● easier to test
public class GuicelessActivity extends Activity {
…
@Override
  protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);




@ContentView(R.layout.main)
public class GuicyActivity extends RoboActivity {
...
TextView       outputText;
...
outputText =(TextView)findViewById(R.id.text_output);




@InjectView(R.id.text_output) TextView outputText;
String appName;
...
appName = getString(R.string.app_name);




@InjectView(R.id.text_output) TextView outputText;
SensorManager sensorManager;
...
sensorManager
     = (SensorManager)getSystemService(SENSOR_SERVICE);




@Inject SensorManager sensorManager;
SomeController someController;
..
someController = new SomeController(this);




@Inject SomeController someController;



public class SomeController {
  Activity hostActivity;

    @Inject
    public SomeController(Activity hostActivity) {
      this.hostActivity = hostActivity;
    }
}
public class GuicelessActivity extends Activity {
  TextView       outputText;
  String         appName;
  SensorManager sensorManager;
  SomeController someController;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      outputText     = (TextView)findViewById(R.id.text_output);
      appName        = getString(R.string.app_name);
      sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
      someController = new SomeController(this);
    }
}




@ContentView(R.layout.main)
public class GuicyActivity extends RoboActivity {
  @InjectView(R.id.text_output)      TextView outputText;
  @InjectResource(R.string.app_name) String appName;
  @Inject                            SensorManager sensorManager;
  @Inject                            SomeController someController;
}
15 LOC → 7 LOC

= more concisene
Dependency Injection (DI)

Makes code ...
● more concise


● more modular


● easier to test
Bindings

public class MyModule extends AbstractModule {

    @Override
    protected void configure() {
      // custom binding go here
    }
}
bind(ISomeService.class).to(SomeServiceDummy.class);
bind(ISomeService.class)
           .toInstance(new SomeServiceReal("yes", 1));
@Inject
@Provides
public AnotherService provideAnotherService(
   ISomeService someService
) {
  return new AnotherService(someService, "bla");
}
Bindings allows for

● wiring up components
● configuring components
Adding
Google Analytics to an Activity
● onCreate → startNewSession


● onResume → trackPageView


● onDestroy → stopSession


● Attributes


● Support code
Component Bloat-Up
● anti pattern: God Class


● low coherence


● tight coupling


● low separation of concernes
public void onCreate(@Observes OnCreateEvent onCreateEvent)
@Inject protected AnalyticsMixin analyticsMixin;
We get:
● loose coupling


● high coherence


● centralized wiring


● centralized configuration
Testability (see wikipedia)
●   controllability: The degree to which it is possible to control the state of the
    component under test (CUT) as required for testing.

●   observability: The degree to which it is possible to observe (intermediate
    and final) test results.

●   isolateability: The degree to which the CUT can be tested in isolation.
●   separation of concerns: The degree to which the CUT has a single,
    well defined responsibility.

●   understandability: The degree to which the CUT is documented or
    self-explaining.

●   automatability: The degree to which it is possible to automate testing of
    the CUT.

●   heterogeneity: The degree to which the use of diverse technologies
    requires to use diverse test methods and tools in parallel.
@RunWith(RobolectricTestRunner.class)
public class SomeServiceTest {
  @Mock private SomeDAO mockDao;
  @Mock private Logger mockLogger;

    private SomeService cut;

    @Before
    public void setUp() throws Exception {
      MockitoAnnotations.initMocks(this);
      cut.someDao = mockDao;
      cut.log = mockLogger;
    }

    @Test
    public void testExecute_willPassWhenNotInBeta() {
      when(mockDao.countSomeStuff()).thenReturn(23);
      assertTrue(cut.hasEnoughStuff());
      verify(mockLogger, times(1)).info("have 23");
    }
}
Testability (see wikipedia)
●   controllability ++
●   observability ++
●   isolateability ++
●   separation of concerns ++
●   understandability +
●   automatability +
●   heterogeneity o
Dependency Injection (DI)

Makes code ...
● more concise


● more modular


● easier to test
References:
●   DI: http://martinfowler.com/articles/injection.html
●   Guice: http://code.google.com/p/google-guice/
●   RoboGuice: https://github.com/roboguice/roboguice
●   Testability:
    http://en.wikipedia.org/wiki/Software_testability
●   Mockito: http://code.google.com/p/mockito/
●   Rebolectric: http://pivotal.github.io/robolectric/


Contact:
●   tom.braun@apps4use.com
●   @tom___b
●   http://play.google.com → GrooveGrid

More Related Content

What's hot

Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
robbiev
 

What's hot (20)

GKAC 2015 Apr. - RxAndroid
GKAC 2015 Apr. - RxAndroidGKAC 2015 Apr. - RxAndroid
GKAC 2015 Apr. - RxAndroid
 
My way to clean android v2 English DroidCon Spain
My way to clean android v2 English DroidCon SpainMy way to clean android v2 English DroidCon Spain
My way to clean android v2 English DroidCon Spain
 
Software engineering ⊇ Software testing
Software engineering ⊇ Software testingSoftware engineering ⊇ Software testing
Software engineering ⊇ Software testing
 
Tools & tricks for testing React applications
Tools & tricks for testing React applications Tools & tricks for testing React applications
Tools & tricks for testing React applications
 
Clean Test
Clean TestClean Test
Clean Test
 
Introduction to Struts 2
Introduction to Struts 2Introduction to Struts 2
Introduction to Struts 2
 
Testing in android
Testing in androidTesting in android
Testing in android
 
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
 
The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202The Ring programming language version 1.8 book - Part 77 of 202
The Ring programming language version 1.8 book - Part 77 of 202
 
Testing Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJavaTesting Android apps based on Dagger and RxJava
Testing Android apps based on Dagger and RxJava
 
Green Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React HooksGreen Custard Friday Talk 21: React Hooks
Green Custard Friday Talk 21: React Hooks
 
The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196The Ring programming language version 1.7 book - Part 75 of 196
The Ring programming language version 1.7 book - Part 75 of 196
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
JSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan ZarnikovJSUG - Google Guice by Jan Zarnikov
JSUG - Google Guice by Jan Zarnikov
 
Advanced Dagger talk from 360andev
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
 
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
BizSpark SF Lightning Talk: "Automated Testing (Unit, Integration and Systems...
 
"Node.js threads for I/O-bound tasks", Timur Shemsedinov
"Node.js threads for I/O-bound tasks", Timur Shemsedinov"Node.js threads for I/O-bound tasks", Timur Shemsedinov
"Node.js threads for I/O-bound tasks", Timur Shemsedinov
 
Testing Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UKTesting Android apps based on Dagger and RxJava Droidcon UK
Testing Android apps based on Dagger and RxJava Droidcon UK
 
Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016Droidcon Berlin Barcamp 2016
Droidcon Berlin Barcamp 2016
 
My way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca editionMy way to clean android - Android day salamanca edition
My way to clean android - Android day salamanca edition
 

Viewers also liked

Droidcon 2013 ui smartphones tam hanna
Droidcon 2013 ui smartphones tam hannaDroidcon 2013 ui smartphones tam hanna
Droidcon 2013 ui smartphones tam hanna
Droidcon Berlin
 
Roduner democratizing business processes with android-based mobile devices
Roduner   democratizing business processes with android-based mobile devicesRoduner   democratizing business processes with android-based mobile devices
Roduner democratizing business processes with android-based mobile devices
Droidcon Berlin
 
Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...
Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...
Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...
Droidcon Berlin
 
Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10min
Corneil du Plessis
 
Spring dependency injection
Spring dependency injectionSpring dependency injection
Spring dependency injection
srmelody
 
Designing and Evaluating a Contextual Mobile Application to Support Situated ...
Designing and Evaluating a Contextual Mobile Application to Support Situated ...Designing and Evaluating a Contextual Mobile Application to Support Situated ...
Designing and Evaluating a Contextual Mobile Application to Support Situated ...
HCI Lab
 

Viewers also liked (20)

Droidcon 2013 ui smartphones tam hanna
Droidcon 2013 ui smartphones tam hannaDroidcon 2013 ui smartphones tam hanna
Droidcon 2013 ui smartphones tam hanna
 
Roduner democratizing business processes with android-based mobile devices
Roduner   democratizing business processes with android-based mobile devicesRoduner   democratizing business processes with android-based mobile devices
Roduner democratizing business processes with android-based mobile devices
 
ASTD Houston Keynote: The Time to Mobilize Learning is Now! by RJ Jacquez
ASTD Houston Keynote: The Time to Mobilize Learning is Now! by RJ JacquezASTD Houston Keynote: The Time to Mobilize Learning is Now! by RJ Jacquez
ASTD Houston Keynote: The Time to Mobilize Learning is Now! by RJ Jacquez
 
Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...
Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...
Droidcon 2010: Android and iPhone - a known Antagonism ? Professor Dr. Kai Ra...
 
Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10min
 
Introduction To Dependency Injection Using Spring.NET
Introduction To Dependency Injection Using Spring.NETIntroduction To Dependency Injection Using Spring.NET
Introduction To Dependency Injection Using Spring.NET
 
Spring beans
Spring beansSpring beans
Spring beans
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Spring and dependency injection
Spring and dependency injectionSpring and dependency injection
Spring and dependency injection
 
Context and Dependency Injection
Context and Dependency InjectionContext and Dependency Injection
Context and Dependency Injection
 
Mobile GUI Design - Web Designer Magazine Article
Mobile GUI Design - Web Designer Magazine ArticleMobile GUI Design - Web Designer Magazine Article
Mobile GUI Design - Web Designer Magazine Article
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
 
Guice - dependency injection framework
Guice - dependency injection frameworkGuice - dependency injection framework
Guice - dependency injection framework
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guice
 
Implement Dependency Injection in Java
Implement Dependency Injection in JavaImplement Dependency Injection in Java
Implement Dependency Injection in Java
 
Eway google-guice presentation
Eway google-guice presentationEway google-guice presentation
Eway google-guice presentation
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
Spring dependency injection
Spring dependency injectionSpring dependency injection
Spring dependency injection
 
Designing and Evaluating a Contextual Mobile Application to Support Situated ...
Designing and Evaluating a Contextual Mobile Application to Support Situated ...Designing and Evaluating a Contextual Mobile Application to Support Situated ...
Designing and Evaluating a Contextual Mobile Application to Support Situated ...
 

Similar to Thomas braun dependency-injection_with_robo_guice-presentation-final

Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
Yekmer Simsek
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
Droidcon Berlin
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's New
Ted Pennings
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
beITconference
 

Similar to Thomas braun dependency-injection_with_robo_guice-presentation-final (20)

Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
Sapphire Gimlets
Sapphire GimletsSapphire Gimlets
Sapphire Gimlets
 
Guice gin
Guice ginGuice gin
Guice gin
 
Devoxx 2012 (v2)
Devoxx 2012 (v2)Devoxx 2012 (v2)
Devoxx 2012 (v2)
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
droidparts
droidpartsdroidparts
droidparts
 
Gwt.create
Gwt.createGwt.create
Gwt.create
 
Struts2 notes
Struts2 notesStruts2 notes
Struts2 notes
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's New
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
Fragments anyone
Fragments anyone Fragments anyone
Fragments anyone
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
 

More from Droidcon Berlin

Droidcon de 2014 google cast
Droidcon de 2014   google castDroidcon de 2014   google cast
Droidcon de 2014 google cast
Droidcon Berlin
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limits
Droidcon Berlin
 
Android industrial mobility
Android industrial mobility Android industrial mobility
Android industrial mobility
Droidcon Berlin
 
From sensor data_to_android_and_back
From sensor data_to_android_and_backFrom sensor data_to_android_and_back
From sensor data_to_android_and_back
Droidcon Berlin
 
new_age_graphics_android_x86
new_age_graphics_android_x86new_age_graphics_android_x86
new_age_graphics_android_x86
Droidcon Berlin
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
Droidcon Berlin
 
Matchinguu droidcon presentation
Matchinguu droidcon presentationMatchinguu droidcon presentation
Matchinguu droidcon presentation
Droidcon Berlin
 
Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3
Droidcon Berlin
 
The artofcalabash peterkrauss
The artofcalabash peterkraussThe artofcalabash peterkrauss
The artofcalabash peterkrauss
Droidcon Berlin
 
Raesch, gries droidcon 2014
Raesch, gries   droidcon 2014Raesch, gries   droidcon 2014
Raesch, gries droidcon 2014
Droidcon Berlin
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
Droidcon Berlin
 
20140508 quantified self droidcon
20140508 quantified self droidcon20140508 quantified self droidcon
20140508 quantified self droidcon
Droidcon Berlin
 
Tuning android for low ram devices
Tuning android for low ram devicesTuning android for low ram devices
Tuning android for low ram devices
Droidcon Berlin
 
Froyo to kit kat two years developing & maintaining deliradio
Froyo to kit kat   two years developing & maintaining deliradioFroyo to kit kat   two years developing & maintaining deliradio
Froyo to kit kat two years developing & maintaining deliradio
Droidcon Berlin
 
Droidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicroDroidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicro
Droidcon Berlin
 
Droidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenbergDroidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenberg
Droidcon Berlin
 

More from Droidcon Berlin (20)

Droidcon de 2014 google cast
Droidcon de 2014   google castDroidcon de 2014   google cast
Droidcon de 2014 google cast
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limits
 
crashing in style
crashing in stylecrashing in style
crashing in style
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
Android industrial mobility
Android industrial mobility Android industrial mobility
Android industrial mobility
 
Details matter in ux
Details matter in uxDetails matter in ux
Details matter in ux
 
From sensor data_to_android_and_back
From sensor data_to_android_and_backFrom sensor data_to_android_and_back
From sensor data_to_android_and_back
 
new_age_graphics_android_x86
new_age_graphics_android_x86new_age_graphics_android_x86
new_age_graphics_android_x86
 
5 tips of monetization
5 tips of monetization5 tips of monetization
5 tips of monetization
 
Testing and Building Android
Testing and Building AndroidTesting and Building Android
Testing and Building Android
 
Matchinguu droidcon presentation
Matchinguu droidcon presentationMatchinguu droidcon presentation
Matchinguu droidcon presentation
 
Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3Cgm life sdk_droidcon_2014_v3
Cgm life sdk_droidcon_2014_v3
 
The artofcalabash peterkrauss
The artofcalabash peterkraussThe artofcalabash peterkrauss
The artofcalabash peterkrauss
 
Raesch, gries droidcon 2014
Raesch, gries   droidcon 2014Raesch, gries   droidcon 2014
Raesch, gries droidcon 2014
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
 
20140508 quantified self droidcon
20140508 quantified self droidcon20140508 quantified self droidcon
20140508 quantified self droidcon
 
Tuning android for low ram devices
Tuning android for low ram devicesTuning android for low ram devices
Tuning android for low ram devices
 
Froyo to kit kat two years developing & maintaining deliradio
Froyo to kit kat   two years developing & maintaining deliradioFroyo to kit kat   two years developing & maintaining deliradio
Froyo to kit kat two years developing & maintaining deliradio
 
Droidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicroDroidcon2013 security genes_trendmicro
Droidcon2013 security genes_trendmicro
 
Droidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenbergDroidcon2013 commercialsuccess rannenberg
Droidcon2013 commercialsuccess rannenberg
 

Recently uploaded

Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
allensay1
 
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
yulianti213969
 

Recently uploaded (20)

Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDINGBerhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
Berhampur CALL GIRL❤7091819311❤CALL GIRLS IN ESCORT SERVICE WE ARE PROVIDING
 
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al MizharAl Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
Al Mizhar Dubai Escorts +971561403006 Escorts Service In Al Mizhar
 
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All TimeCall 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
Call 7737669865 Vadodara Call Girls Service at your Door Step Available All Time
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Phases of Negotiation .pptx
 Phases of Negotiation .pptx Phases of Negotiation .pptx
Phases of Negotiation .pptx
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Pre Engineered Building Manufacturers Hyderabad.pptx
Pre Engineered  Building Manufacturers Hyderabad.pptxPre Engineered  Building Manufacturers Hyderabad.pptx
Pre Engineered Building Manufacturers Hyderabad.pptx
 
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
obat aborsi bandung wa 081336238223 jual obat aborsi cytotec asli di bandung9...
 
UAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur Dubai
UAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur DubaiUAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur Dubai
UAE Bur Dubai Call Girls ☏ 0564401582 Call Girl in Bur Dubai
 
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book nowPARK STREET 💋 Call Girl 9827461493 Call Girls in  Escort service book now
PARK STREET 💋 Call Girl 9827461493 Call Girls in Escort service book now
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
Unveiling Falcon Invoice Discounting: Leading the Way as India's Premier Bill...
 
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
Only Cash On Delivery Call Girls In Sikandarpur Gurgaon ❤️8448577510 ⊹Escorts...
 
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
Chennai Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Av...
 
Arti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdfArti Languages Pre Seed Teaser Deck 2024.pdf
Arti Languages Pre Seed Teaser Deck 2024.pdf
 
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTSJAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR  ESCORTS
JAJPUR CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN JAJPUR ESCORTS
 
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTSDurg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
Durg CALL GIRL ❤ 82729*64427❤ CALL GIRLS IN durg ESCORTS
 
Nanded Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Nanded Call Girl Just Call 8084732287 Top Class Call Girl Service AvailableNanded Call Girl Just Call 8084732287 Top Class Call Girl Service Available
Nanded Call Girl Just Call 8084732287 Top Class Call Girl Service Available
 
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
Escorts in Nungambakkam Phone 8250092165 Enjoy 24/7 Escort Service Enjoy Your...
 
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
Ooty Call Gril 80022//12248 Only For Sex And High Profile Best Gril Sex Avail...
 

Thomas braun dependency-injection_with_robo_guice-presentation-final

  • 1. Dependency Injection with RoboGuice ©2013 Tom Braun <tom.braun@apps4use.com>
  • 2.
  • 3. {concept} Inversion of Control (IoC) {concept} Dependency Injection (DI) Googe Guice Spring core PicoContainer Plexus Android RoboGuice Dagger Annotations
  • 4. Dependency Injection (DI) Makes code ... ● more concise ● more modular ● easier to test
  • 5. public class GuicelessActivity extends Activity { … @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); @ContentView(R.layout.main) public class GuicyActivity extends RoboActivity {
  • 6. ... TextView outputText; ... outputText =(TextView)findViewById(R.id.text_output); @InjectView(R.id.text_output) TextView outputText;
  • 7. String appName; ... appName = getString(R.string.app_name); @InjectView(R.id.text_output) TextView outputText;
  • 8. SensorManager sensorManager; ... sensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); @Inject SensorManager sensorManager;
  • 9. SomeController someController; .. someController = new SomeController(this); @Inject SomeController someController; public class SomeController { Activity hostActivity; @Inject public SomeController(Activity hostActivity) { this.hostActivity = hostActivity; } }
  • 10. public class GuicelessActivity extends Activity { TextView outputText; String appName; SensorManager sensorManager; SomeController someController; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); outputText = (TextView)findViewById(R.id.text_output); appName = getString(R.string.app_name); sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); someController = new SomeController(this); } } @ContentView(R.layout.main) public class GuicyActivity extends RoboActivity { @InjectView(R.id.text_output) TextView outputText; @InjectResource(R.string.app_name) String appName; @Inject SensorManager sensorManager; @Inject SomeController someController; }
  • 11. 15 LOC → 7 LOC = more concisene
  • 12. Dependency Injection (DI) Makes code ... ● more concise ● more modular ● easier to test
  • 13. Bindings public class MyModule extends AbstractModule { @Override protected void configure() { // custom binding go here } }
  • 15. bind(ISomeService.class) .toInstance(new SomeServiceReal("yes", 1));
  • 16. @Inject @Provides public AnotherService provideAnotherService( ISomeService someService ) { return new AnotherService(someService, "bla"); }
  • 17. Bindings allows for ● wiring up components ● configuring components
  • 18. Adding Google Analytics to an Activity ● onCreate → startNewSession ● onResume → trackPageView ● onDestroy → stopSession ● Attributes ● Support code
  • 19. Component Bloat-Up ● anti pattern: God Class ● low coherence ● tight coupling ● low separation of concernes
  • 20. public void onCreate(@Observes OnCreateEvent onCreateEvent)
  • 22. We get: ● loose coupling ● high coherence ● centralized wiring ● centralized configuration
  • 23. Testability (see wikipedia) ● controllability: The degree to which it is possible to control the state of the component under test (CUT) as required for testing. ● observability: The degree to which it is possible to observe (intermediate and final) test results. ● isolateability: The degree to which the CUT can be tested in isolation. ● separation of concerns: The degree to which the CUT has a single, well defined responsibility. ● understandability: The degree to which the CUT is documented or self-explaining. ● automatability: The degree to which it is possible to automate testing of the CUT. ● heterogeneity: The degree to which the use of diverse technologies requires to use diverse test methods and tools in parallel.
  • 24. @RunWith(RobolectricTestRunner.class) public class SomeServiceTest { @Mock private SomeDAO mockDao; @Mock private Logger mockLogger; private SomeService cut; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); cut.someDao = mockDao; cut.log = mockLogger; } @Test public void testExecute_willPassWhenNotInBeta() { when(mockDao.countSomeStuff()).thenReturn(23); assertTrue(cut.hasEnoughStuff()); verify(mockLogger, times(1)).info("have 23"); } }
  • 25. Testability (see wikipedia) ● controllability ++ ● observability ++ ● isolateability ++ ● separation of concerns ++ ● understandability + ● automatability + ● heterogeneity o
  • 26. Dependency Injection (DI) Makes code ... ● more concise ● more modular ● easier to test
  • 27. References: ● DI: http://martinfowler.com/articles/injection.html ● Guice: http://code.google.com/p/google-guice/ ● RoboGuice: https://github.com/roboguice/roboguice ● Testability: http://en.wikipedia.org/wiki/Software_testability ● Mockito: http://code.google.com/p/mockito/ ● Rebolectric: http://pivotal.github.io/robolectric/ Contact: ● tom.braun@apps4use.com ● @tom___b ● http://play.google.com → GrooveGrid