AndroidAPS/app/src/main/java/info/nightscout/androidaps/dependencyInjection/dependency-injection-todo.txt
2019-12-23 13:27:15 +01:00

16 lines
1.3 KiB
Plaintext

PreferenceActivity is an Example how to make an Activity injectable.
We might undo that as we don't actually have us inject things.
MyPreferencesFragment is an injectable Fragment. Here we actually have Dagger2 provide us an InsulinOrefFreePeakPlugin instance.
If we use multiple Fragments, we should generate a base-class. Then we only have to add a "provides***Fragment" to the FragmentsModule and derive from that class.
InsulinOrefFreePeakPlugin is an example how to get things injected via the constructor.
You could call "new InsulinOrefFreePeakPlugin(new SPImpl(SPImpl(PreferenceManager.getDefaultSharedPreferences(context))), new ResourceHelper())"... but Dagger will resolve that for you in MainApp. :)
SPImpl is an example how to bind an implementation to an Interface via Dagger.
ResourceHelper is an example how to generate simple classes that Dagger can auto-resolve how to inject them. No need for a provider here.
ResourceHelper might have a weak reference at some point and not a static dependency on MainApp... but at least we reduced the static dependencies within a plugin.
In order to Test: Any dependency of InsulinOrefFreePeakPlugin is passed via the constructor. Instead of static mocking MainApp you now can Mock ResourceHelper with a very small interface.