i’d expect a provides hiding the hard cast is the only way since it is a cast up and can’t be verified simply. though i’d guess you could validate it at compile time it would be expensive.
🙏 1
m
miqbaldc
07/15/2021, 2:34 AM
Ah I see, doing the hard cast was our current implementation 😞
something like this:
Copy code
// TheModule.kt
// `as?` or using the pre-conditions by calling: Preconditions.checkNotNull(...)
@InstallIn(ActivityComponent::class)
@Module
object TheModule {
@Provides fun fragmentActivity(@ActivityContext context: Context) = context as? FragmentActivity
}
// the injected class: MyClass.kt
class MyClass @Inject constructor(
val fragmentActivity: FragmentActivity?
)