Roboguice

1,220 views
1,006 views

Published on

Short overview of Roboguice framework.

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,220
On SlideShare
0
From Embeds
0
Number of Embeds
87
Actions
Shares
0
Downloads
22
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Roboguice

  1. 1. Roboguice also dependency injection framework Paweł Byszewski
  2. 2. Cofiguration JARs roboguice.xml Modules
  3. 3. Cofiguration
  4. 4. Cofiguration
  5. 5. Bindings Interface to implementation Adnotation bindings Instance bindings Provides methods and objects On demand
  6. 6. Bindings - interface to implementation
  7. 7. Bindings - interface to implementation
  8. 8. Bindings Interface to implementation Adnotation bindings Instance bindings Provides methods and objects On demand
  9. 9. Bindings - adnotation binding
  10. 10. Bindings - adnotation binding
  11. 11. Bindings Interface to implementation Adnotation bindings Instance bindings Provides methods and objects On demand
  12. 12. Bindings - instance
  13. 13. Bindings Interface to implementation Adnotation bindings Instance bindings Provides methods and objects On demand
  14. 14. Bindings - providers
  15. 15. Bindings - providers
  16. 16. Bindings - providers
  17. 17. Bindings Interface to implementation Adnotation bindings Instance bindings Provides methods and objects On demand
  18. 18. Bindings - on demand
  19. 19. Bindings - on demand 08-27 16:44:31.182:INFO/EU.SOFTISLAND.MOBILEWARSAW/InstanceBindingActivity4.java:30(22432): main Serwer url: 127.0.0.1 08-27 16:44:31.182:INFO/EU.SOFTISLAND.MOBILEWARSAW/InstanceBindingActivity4.java:32(22432): main TIMEOUT: 15
  20. 20. Injection points
  21. 21. Injection points
  22. 22. Injection points
  23. 23. Injection points
  24. 24. Injection points
  25. 25. @ContentView, Resource etc.
  26. 26. @ContentView, Resource etc.
  27. 27. @ContentView, Resource etc.
  28. 28. @ContentView, Resource etc.
  29. 29. @ContentView, Resource etc.
  30. 30. @ContentView, Resource etc.
  31. 31. @ContentView, Resource etc.
  32. 32. System service Injection PackageInfo LocationManager WindowManager ActivityManager PowerManager AlarmManager NotificationManager KeyguardManager Vibrator SensorManager. TelephonyManager AudioManager LayoutInflater SearchManager AccountManager WifiManager InputMethodManager ConnectivityManager http://github.com/roboguice/roboguice/blob/master/roboguice/src/main/java/roboguice/config/ DefaultRoboModule.java
  33. 33. @Observes
  34. 34. @Observes OnActivityResultEvent OnConfigurationChangeEvent OnContentChangeEvent OnCreateEvent OnDestroyEvent OnNewIntentEvent OnPauseEvent OnRestartEvent OnResumeEvent OnStartEvent OnStopEvent
  35. 35. @Observes
  36. 36. @Observes
  37. 37. Async tasks AsyncTask <String, Integer, Boolean> Boolean doInBackground(String... params) void onPreExecute() void onPostExecute(Boolean aBoolean) void onProgressUpdate(Integer... values) void onCancelled(Boolean aBoolean) RoboAsyncTask <Boolean> Boolean call() void onInterrupted(Exception e) void onException(Exception e) void onThrowable(Throwable t) void onFinally() void onPreExecute() void onSuccess(Boolean aBoolean)
  38. 38. Async tasks AsyncTask <String, Integer, Boolean> + progress update - exception handle RoboAsyncTask <Boolean> - progress update + exception handle + injections
  39. 39. Application, Context, Activity ... Context Activity RoboActivity Service RoboService Application
  40. 40. Application, Context, Activity ...
  41. 41. Application, Context, Activity ...
  42. 42. Scopes Singleton ContextSingleton
  43. 43. Scopes
  44. 44. Mixing scopes
  45. 45. Robot legs problem
  46. 46. The Injector creation process Phase 1: Static Building Phase 2: Injection Phase 3: Singleton Preloading
  47. 47. HTC Desire HD - it takes 600 ms HTC Wildfire - it takes 1.8 to 2.4 s
  48. 48. Know your dependency tree Avoid static injection like the plague Avoid too many or complex modules Create a development mode injector to avoid eager loading of all singletons Use a RoboSplashActivity as a last resort
  49. 49. Best practices Keep constructors as hidden as possible Inject only direct dependencies Avoid cyclic dependencies Modules should be fast and side-effect free Be careful about I/O in Providers Avoid conditional logic in modules Single responsibility principle
  50. 50. pawell.b@gmail.com pbs@touk.pl
  51. 51. pawell.b@gmail.com pbs@touk.pl

×