Reputation: 309
If there is @inject, then it means there must be @provide? inject field gets its value from @provide method of module?
Upvotes: 1
Views: 491
Reputation: 81549
Yes if you use Module
@Module
public class SomeModule {
@Provides
Unscoped unscoped() {
return new Unscoped();
}
@Provides
@Singleton
Scoped scoped() {
return Scoped();
}
}
BUT classes with @Inject
constructor get automatically appended to your scoped component even if no module is specified for it:
@Singleton
public class Scoped {
@Inject
public Scoped() {
}
}
public class Unscoped {
@Inject
public Unscoped() {
}
}
Upvotes: 3
Reputation: 1271
If there is @Inject annotation then it's dependency can be provided in two ways :
By Using Provides annotation in module
@Provides
TasksPresenter provide TasksPresenter(TasksRepository tasksRepository, TasksContract.View tasksView) {
return new TasksPresenter(tasksRepository,tasksView);
}
By Using Constructor Injection
@Inject
TasksPresenter(TasksRepository tasksRepository, TasksContract.View tasksView) {
mTasksRepository = tasksRepository;
mTasksView = tasksView;
}
One thing to observe here is Constructor Injection solve two thing
Upvotes: 1