-
-
Save pkliang/a68dc2006a1e5cda87660f0d183bb8cc to your computer and use it in GitHub Desktop.
A demonstration about how to inject BindingAdapters with Dagger Hilt.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BindingScoped.kt | |
@Scope | |
@Retention(AnnotationRetention.BINARY) | |
annotation class BindingScoped | |
------------------------------------------------------- | |
CustomBindingComponent.kt | |
@BindingScoped | |
@DefineComponent(parent = ApplicationComponent::class) | |
interface CustomBindingComponent : DataBindingComponent | |
------------------------------------------------------- | |
CustomBindingComponentBuilder.kt | |
@DefineComponent.Builder | |
interface CustomBindingComponentBuilder { | |
fun build(): CustomBindingComponent | |
} | |
------------------------------------------------------- | |
CustomBindingEntryPoint.kt | |
@EntryPoint | |
@BindingScoped | |
@InstallIn(CustomBindingComponent::class) | |
interface CustomBindingEntryPoint { | |
@BindingScoped | |
fun getImageBindingAdapter(): ImageBindingAdapter | |
} | |
------------------------------------------------------- | |
MyApp.kt | |
@HiltAndroidApp | |
class MyApp : Application() { | |
@Inject | |
lateinit var bindingComponentProvider: Provider<CustomBindingComponentBuilder> | |
override fun onCreate() { | |
super.onCreate() | |
DataBindingUtil.setDefaultComponent(bindingComponentProvider.get().build()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment