Created
May 3, 2012 20:47
-
-
Save davespanton/2589240 to your computer and use it in GitHub Desktop.
Assisted Injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the factory interface | |
public interface SMSSendingAlarmFactory { | |
public SMSSendingAlarm create(Context context); | |
} | |
// in the module class | |
protected void configure() { | |
// ... various other bindings ... | |
install(new FactoryModuleBuilder() | |
.build(SMSSendingAlarmFactory.class)); | |
} | |
// the assisted injection constructor | |
@AssistedInject | |
public SMSSendingAlarm(@Assisted Context context) { | |
this.context = context; | |
} | |
// in use elsewhere in the application... | |
private SMSSendingAlarm smsAlarm; | |
@Inject | |
private SMSSendingAlarmFactory smsAlarmFactory; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
smsAlarm = smsAlarmFactory.create(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment