Colton Idle
11/27/2021, 7:20 PMCrashReporterService
interface, and a real impl called FirebaseCrashReporterService
. Both the interface and impl are on the Dependency graph, and so... nothing prevents someone from Injecting FirebaseCrashReporterService.
Is there anything I can do to hide my real impls so that people only use the interface?Nicholas Doglio
11/27/2021, 7:35 PMCrashReporterService
if you're using Dagger favor just injecting the interface"jw
11/27/2021, 7:45 PMDaniel Perez
11/27/2021, 8:07 PMursus
11/28/2021, 2:35 AMColton Idle
11/28/2021, 2:51 AMColton Idle
11/28/2021, 2:53 AMursus
11/28/2021, 2:55 AM@Provides fun foo(): Foo = FooImpl()
Colton Idle
11/28/2021, 3:03 AMursus
11/28/2021, 3:15 AMjw
11/28/2021, 4:06 AMColton Idle
11/28/2021, 6:12 AMursus
11/28/2021, 12:55 PMjw
11/28/2021, 12:59 PMursus
11/28/2021, 3:01 PMColton Idle
11/28/2021, 6:03 PMinterface CrashReporterService {
fun logFatal(e: Exception)
}
class FirebaseCrashReporterService : CrashReporterService {
override fun logFatal(e: Exception) {
// do something
}
}
@Module
@InstallIn(SingletonComponent::class)
abstract class AppInterfaceModule {
@Singleton
@Binds
abstract fun bindsCrashReporterService(
@Named("placeholder_qualifier") service: FirebaseCrashReporterService
): CrashReporterService
}
@Module
@InstallIn(SingletonComponent::class)
class AppImplModule {
@Singleton
@Provides
@Named("placeholder_qualifier")
fun bindsCrashReporterService(): FirebaseCrashReporterService {
return FirebaseCrashReporterService()
}
}
ursus
11/28/2021, 8:18 PMColton Idle
11/29/2021, 4:23 PMursus
11/29/2021, 5:10 PM@Module
object FirebaseCrashReporterModule {
@JvmStatic
@Provides
fun firebaseCrashReporter(dependencies..) : CrashReporter {
return FirebaseCrashReporter(...)
}
}
that's itColton Idle
11/30/2021, 2:31 AMobject
so it should be fine?ursus
11/30/2021, 3:07 AM