asc*_*sco 3 android dependency-injection dagger-2
我正在玩Dagger 2.
我有以下内容Module:
@Module
public class GameSetupModule {
@Provides
@Singleton
GameSetup provideGameSetup() {
return new GameSetup();
}
}
Run Code Online (Sandbox Code Playgroud)
和根据Component:
@Singleton
@Component(modules = {GameSetupModule.class})
public interface GameSetupComponent {
GameSetup provideGameSetup();
void inject(SetupActivity activity);
// void inject(Fragment fragment);
void inject(SetupCompletedFragment fragment);
void inject(SelectQuarterLengthFragment fragment);
void inject(SelectTeamColorsFragment fragment);
void inject(SelectUserRoleFragment fragment);
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,GameSetup将注入几个不同的片段,如下所示:
@Inject
GameSetup gameSetup;
onCreate(){
getGameSetupComponent().inject(this);
}
Run Code Online (Sandbox Code Playgroud)
It works fine when implemented as seen above, the injection does not work though when I just use a single method
void inject(Fragment fragment);
Run Code Online (Sandbox Code Playgroud)
for all Fragments.
Am I doing something wrong or is this even intended to have more control over where the GameSetup may be injected and where it may not be available?
| 归档时间: |
|
| 查看次数: |
2529 次 |
| 最近记录: |