Loading presentation...

Present Remotely

Send the link below via email or IM


Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.


@inject presentation

Introduction to dependency injection.


on 29 August 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of @inject presentation

@inject String name;
Inversion of control
Martin Fowler
usual case
List<Person> contacts = Contacts.query(...);
copy & paste !?
Lister<Person> contactLister = new OnlineContactLister(connection, ...);
Change specs !?
Lister<Person> contactLister = Creator.createContactLister(connection);

//in settings file, set ContactLister to NetContactLister
Constructor parameters ??
//injector settings
Lister<Person> => NetPersonLister

//injector usage
@Inject Lister<Person> contactLister;
- maps interface to implementation
- construct and inject objects
- construct and inject parameters
refactor with injection
only change injector settings !
injector modules
Collection of injection settings
public class netRunModule {
Lister<Person> => NetContactLister

public class localRunModule {
Lister<Person> => DBConactLister
public class TestModule {
Lister<Person> => DummyLister
Constructor injection
@Inject public Clazz (Dependency d) {
this.mD = d;
Method injection
@inject void setDependency (Dependency d) {
this.mD = d;
Member injection
@inject private Dependency mD;
// impossible without injection FW !
- clarify dependencies
- easy refactor
- perfect for testing
Injection frameworks
- Pico: minimal, efficient
- Guice: full-featured, runtime
- Spring
- Roboguice: based on guice, Android specific features
- Proton: small footprint
- Dagger: for Android, static injection
Activity, Application, etc instantiated by the system !
public class RoboActivity extends Activity {
public void onCreate(...) {
Injector i = RoboGuice.getInjector(applicationContext);
Roboguice usage
public class MyClass extends RoboActivity {
@inject Something mS;

public onCreate(...) {
// mS == null
// mS instantiated !
- instance / request
- context / session
- application / singleton
Full transcript