Roboguice
also dependency injection framework
Paweł Byszewski
Cofiguration
JARs
roboguice.xml
Modules
Cofiguration
Cofiguration
Bindings
Interface to implementation
Adnotation bindings
Instance bindings
Provides methods and objects
On demand
Bindings - interface to implementation
Bindings - interface to implementation
Bindings
Interface to implementation
Adnotation bindings
Instance bindings
Provides methods and objects
On demand
Bindings - adnotation binding
Bindings - adnotation binding
Bindings
Interface to implementation
Adnotation bindings
Instance bindings
Provides methods and objects
On demand
Bindings - instance
Bindings
Interface to implementation
Adnotation bindings
Instance bindings
Provides methods and objects
On demand
Bindings - providers
Bindings - providers
Bindings - providers
Bindings
Interface to implementation
Adnotation bindings
Instance bindings
Provides methods and objects
On demand
Bindings - on demand
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
Injection points
Injection points
Injection points
Injection points
Injection points
@ContentView, Resource etc.
@ContentView, Resource etc.
@ContentView, Resource etc.
@ContentView, Resource etc.
@ContentView, Resource etc.
@ContentView, Resource etc.
@ContentView, Resource etc.
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
@Observes
@Observes
OnActivityResultEvent
OnConfigurationChangeEvent
OnContentChangeEvent
OnCreateEvent
OnDestroyEvent
OnNewIntentEvent
OnPauseEvent
OnRestartEvent
OnResumeEvent
OnStartEvent
OnStopEvent
@Observes
@Observes
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)
Async tasks
AsyncTask <String, Integer, Boolean>
+ progress update
- exception handle
RoboAsyncTask <Boolean>
- progress update
+ exception handle
+ injections
Application, Context, Activity ...
Context
Activity
RoboActivity
Service
RoboService
Application
Application, Context, Activity ...
Application, Context, Activity ...
Scopes
Singleton
ContextSingleton
Scopes
Mixing scopes
Robot legs problem
The Injector creation process
Phase 1: Static Building
Phase 2: Injection
Phase 3: Singleton Preloading
HTC Desire HD -
it takes 600 ms
HTC Wildfire -
it takes 1.8 to 2.4 s
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
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
pawell.b@gmail.com
pbs@touk.pl
pawell.b@gmail.com
pbs@touk.pl

Roboguice