aniruddha dhamal
06/25/2021, 4:23 PMradityagumay
06/27/2021, 2:50 AManiruddha dhamal
06/28/2021, 2:19 PMinterface Car {
fun start()
}
class CarImpl {
fun start() {...}
}
@Module
@InstallIn(SingletonComponent::class)
object CarModule {
@Provides
@Singleton
fun provideCar(context: Context): Car {
return CarImpl(context)
}
}
fun Context.car() {
// How to access Car here? In extension function.
}
How do i inject/access Car here?radityagumay
06/28/2021, 2:24 PManiruddha dhamal
06/29/2021, 5:02 PMradityagumay
06/30/2021, 2:06 AMradityagumay
06/30/2021, 2:06 AMradityagumay
06/30/2021, 2:07 AMradityagumay
06/30/2021, 2:12 AMinterface AppFooProvider {
val provider: FooProvider
interface FooProvider {
val foo: Foo
}
}
class MyApp : Application(), AppFooProvider {
@Inject
internal lateinit var foo: Foo
override val provider: FooProvider by lazy {
object : FooProvider {
override val foo: Foo
get() = this@MyApp.foo
}
}
override fun onCreate(bundle: Bundle) {
super.onCreate(bundle)
DaggerAppComponent.factory()
.create(this)
.inject(this)
}
}
// usage
fun Context.getFoo() : Foo {
return (this.applicationContext as AppFooProvider).provider.foo
}
aniruddha dhamal
06/30/2021, 4:41 AM