I created Activity, ViewModel, Modules for Toothpick and Authenticator.
@Singleton
public class GetSmsViewModel {
@Inject Application app;
@Inject Authenticator authenticator;
...
}
public class GetSmsActivity extends AppCompatActivity {
private Scope appScope;
@Inject GetSmsViewModel mGetSmsViewModel;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
appScope = Toothpick.openScope(getApplication());
appScope.installModules(new DIModule(getApplication()), new DataModule());
super.onCreate(savedInstanceState);
Toothpick.inject(this, appScope);
...
}
}
public class DIModule extends Module {
public MagicDeliveryMainModule(Application application) {
bind(GetSmsViewModel.class).toInstance(new GetSmsViewModel());
bind(Application.class).toInstance(application);
bind(Authenticator.class).toInstance(new Authenticator());
}
}
In the documentation for the Toothpick is written : "If Toothpick creates an instance, it will always inject its dependencies." , but after Toothpick.inject(this, appScope);
mGetSmsViewModel.app == null and mGetSmsViewModel.authenticator == null . And after Toothpick.inject(mGetSmsViewModel, appScope); app and authenticator fields become injected.
so it should be?