Colton Idle
07/25/2023, 9:28 PMclass Bar @Inject constructor (random: Thing)
and I don't need a provides method (except for Thing)
. Everything is good.
Now whats the best way to make Bar an interface?
interface Bar
class ConcreteBar @Inject constructor (randomButOnlyNeededForConcreteImpl: Thing): Bar
I have this provides statement, and it works... but kinda annoying to repeat the injection params since I am already doing it at the class with the @Inject annotation. Am I doing something wrong?
@Provides
@Singleton
fun provideBar(
randomButOnlyNeededForConcreteImpl: Thing)
): Bar {
return ConcreteBar(randomButOnlyNeededForConcreteImpl)
}
Nicholas Doglio
07/25/2023, 9:32 PM@Module
@InstallIn(SingletonComponent::class)
interface MyBindsModule {
@Binds
fun bindsBar(impl: ConcreteBar): Bar
}
Nicholas Doglio
07/25/2023, 9:33 PMConcreteBar
directly with @Singleton
instead of putting it on the provides or binds methodNicholas Doglio
07/25/2023, 9:34 PMColton Idle
07/25/2023, 9:37 PMColton Idle
07/25/2023, 9:37 PMColton Idle
07/25/2023, 9:38 PMColton Idle
07/25/2023, 9:41 PMjava.lang.IllegalStateException: There are multiple DataStores active for the same file: preferences.preferences_pb. You should either maintain your DataStore as a singleton or confirm that there is no two DataStore's active on the same file (by confirming that the scope is cancelled).
Colton Idle
07/25/2023, 9:41 PMColton Idle
07/25/2023, 9:41 PMNicholas Doglio
07/25/2023, 9:43 PMConcreteBar
file and know it's a singleton without having to look at another file, does that make sense?Nicholas Doglio
07/25/2023, 9:44 PMColton Idle
07/25/2023, 11:16 PMColton Idle
07/28/2023, 2:25 PMstatic
and how that actually translatesNicholas Doglio
07/28/2023, 2:43 PM@Provides
methods objects
and Dagger will optimize it correctly.Colton Idle
07/28/2023, 6:49 PM