1
votes

I been working with Squares dagger for a while. It works really decent on fragments and activity but I have problems getting some of the injects in other places.

How would one for example inject into a class that extends from BaseAdapter?

BaseAdapters have no context. so I can not get the activity context or application context. Not without providing this myself in the constructor (which means I am providing a dependancy the old way?)

1

1 Answers

0
votes

You make your Application class create the ObjectGraph object and pass it into a class that will keep it. This class, you can make it like a "Injector" class that holds a static instance of the ObjectGraph.

Here it's an example: https://github.com/freezy/android-xbmcremote-sandbox/blob/master/app/src/main/java/org/xbmc/android/app/injection/Injector.java

Then from your Fragment,Adapter or Activity, you can do:

Injector.inject(this) ---> this == your fragment, your adapter or activity ...considering that it is properly registered in your 'Modules'.