I'm using Dagger 2 and the Repository pattern in Android and am getting tripped up by which scope I should be using for the repository's dependencies and the tradeoffs of using them.
Generally I create a repository per feature. So if we're talking about the registration feature then I'd create a RegistrationRepository. The RegistrationRepository would have 3 different data sources, RegistrationNetworkSource, RegistrationDiscSource and RegistrationMemorySource. When my Activity makes a request to the RegistrationRepository the repo will create an RxJava observable and return it to the activity. The activity can then subscribe to the observable and await the result. If the activity happens to undergo a configuration change before the observable returns a result then the observable can be cached in a separate class that is scoped to the application life cycle and after the activity is re-created it can grab this cached observable and resubscribe to it. And this is where my confusion starts. If my observable is being cached in a class that is scoped to the application scope does that mean that the 3 repository data sources also need to be scoped to the application scope?
My gut tells me that I should scope them to the Application scope. Doing this would allow each source to perform a long running data fetching task that could continue even if the Activity that the request came from undergoes a configuration change. There'd be one instance per app and they'd always be available for use. That sounds great, but doesn't that end up wasting resources? If registration is the first screen of my app and the user spends the rest of their time on the HomeActivity or some other place, then why should the 3 Registration data sources still be alive?