Я могу добавить свой RepositoryClass в свой NotificationService
Я пытаюсь внедрить мой ToDoRepository в мой ToDoDeleteNotificationService и всегда получаю этот репозиторий нулевым. Я не знаю, нужно ли мне делать еще один Модуль или я не могу сделать это в IntentService.
@Module
public class ToDoRepositoryModule {
@Provides
@Singleton
ToDoDatabase provideDatabase(Application application) {
return Room.databaseBuilder(application,
ToDoDatabase.class, "ToDo.db")
.build();
}
@Provides
@Singleton
ToDoDao provideUserDao(ToDoDatabase database) {
return database.toDoDao();
}
@Provides
@Singleton
AppExecutors provideAppExecutors() {
return new AppExecutors();
}
@Provides
@Singleton
ToDoRepository providesToDoRepository(ToDoDao toDoDao, AppExecutors appExecutors) {
return new ToDoRepository(toDoDao, appExecutors);
}
}
- Когда вызывается мой класс TodoDeleteNotiricationService, я получаю свой todoId, так как мой репозиторий пуст
public class ToDoDeleteNotificationService extends IntentService {
@Inject
ToDoRepository mToDoRepository;
public ToDoDeleteNotificationService() {
super("ToDoDeleteNotificationService");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
assert intent != null;
String toDoId = intent.getStringExtra(ToDoNotificationsService.TODO_MODEL_KEY);
mToDoRepository.deleteToDo(toDoId);
}
}
-
@Singleton
@Component(modules = {ToDoRepositoryModule.class,
ActivityBindingModule.class,
AppModule.class,
AndroidSupportInjectionModule.class})
public interface AppComponent extends AndroidInjector<ToDoApplication>{
ToDoRepository getToDoRepository();
@Component.Builder
interface Builder{
@BindsInstance
AppComponent.Builder application(Application application);
AppComponent build();
}
}