Reputation: 2720
i'm trying to update this below code to dagger2, but i get error for ObjectGraph
:
import dagger.ObjectGraph;
public class App extends Application {
private static App instance;
private ObjectGraph objectGraph;
public App() {
instance = this;
}
@Override
public void onCreate() {
super.onCreate();
objectGraph = ObjectGraph.create(new AppModule());
}
public static void injectMembers(Object object) {
getInstance().objectGraph.inject(object);
}
public static <T>T get(Class<T> klass) {
return getInstance().objectGraph.get(klass);
}
public static App getInstance() {
return instance;
}
}
how can i update that to and which class must be use instead of ObjectGraph
?
injectMembers
used in this class
public class MyJobManager extends JobManager {
public MyJobManager(Context context) {
super(context, new Configuration.Builder(context)
.injector(new DependencyInjector() {
@Override
public void inject(BaseJob baseJob) {
App.injectMembers(baseJob);
}
})
.build());
}
}
now how can i inject with component?
my component:
@ActivitiesScope
@Component(dependencies = GithubApplicationComponent.class)
public interface ApplicationComponent {
void inject(ActivityRegister activityRegister);
void inject(ActivityStartUpApplication activityStartUpApplication);
void inject(GetLatestRepositories getLatestRepositories);
}
Upvotes: 1
Views: 1597
Reputation: 93728
Dagger 2 doesn't use an ObjectGraph. It doesn't use anything as its replacement. Dagger1 did injection at runtime via reflection and used the ObjectGraph to provide that functionality. Dagger 2 does injection at compile time, thus it doesn't need a runtime object to represent the graph. Instead you'd want to build a component that links the modules you with to provide. You can then inject using that component.
See https://google.github.io/dagger/dagger-1-migration.html for more details.
Upvotes: 3