Hi im trying to figure out how to do a clean third party injection. I want to inject Otto bus properly into my services and activities. Iv seen that you can use inject on constructor, but since I dont have any constructor with Android, i wonder how I can then inject my bus.
Iv created a module which provides a new instance of the bus. Iv also created a component which has an interface for the Bus object.
But how can I get this injected and where should I initiate my graph?
Since the objectGraph from Dagger 1 is removed, i use the Dagger_.... component and create() in the application class, but how should I inject it into whatever activity or service?
Should I create the component in every onCreate and get the bus from there? Or is it possible to @Inject like Dagger 1? Please tell me because right now it seems much more clumpy and complicated than Dagger 1 way of doing it.
@Component(modules = EventBusModule.class)
@Singleton
public interface EventBus {
Bus bus();
}
@Module
public class EventBusModule {
@Provides
@Singleton
public Bus provideBus() {
return new Bus(ThreadEnforcer.ANY);
}
}
All i want to be able to do is:
public class WearService extends WearableListenerService {
private static final String TAG = WearService.class.getSimpleName();
@Inject
protected Bus bus;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
bus.register(this);
return START_STICKY;
}
}
I look at this example(https://github.com/LiveTyping/u2020-mvp) and see that its possible, but not sure how things is hanging together.