Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependency Injection on Android

Thanh Le
February 27, 2016

Dependency Injection on Android

Presentation for Android Dev Saigon meetup #3
Twitter: http://twitter.com/lenguyenthanh
Github: http://github.com/lenguyenthanh

Thanh Le

February 27, 2016
Tweet

Other Decks in Programming

Transcript

  1. Dependency Injection on Android Thanh Le(Commonwealth Vietnam)
 Twitter: @lenguyenthanh
 Github:

    github/lenguyenthanh
 Facebook: fb/lenguyenthanh Android Saigon Slack: @thanh
  2. 1. What is Dependency Injection(DI)? 2. Why DI? 3. DI

    libraries 4. Dagger 2 1. Api 1. Provide dependencies 2. Request dependencies 3. Component Api 4. Scope Api 5. Example and best practices
  3. What is Dependency Injection(DI)? Dependency injection is all about separating

    process of creating objects from where them are being used . Ask for things, don’t look for things.
  4. Why Dependency Injection? 1. Single Responsibility. 2. Easy to switch

    the implementation detail. 3. Split to two kinds of object: one for doing things and one for creating others. 4. Make testing easier.
  5. DI libraries for Android 1. Google Guice: 
 Stable, solid,

    and flexible but heavily use reflection in Runtime to generate code. So it effect start-up time longer and memory usage. 2. Dagger 1: 1. Successor of Guice, faster then Guice because of generating code in compile time. 2. It still use reflection code when generating code and creating graph composition at Runtime. 3. Hard to manage scope of object. 3. Dagger 2: 1. Successor of Dagger 1 with no reflection, graph object composition at compile time. 2. Increase performance: Google said their apps gained 13% of processor performance to compare with Dagger 1. 3. Provides mechanism to manage object scope.