Kshitij Patil
11/28/2022, 6:47 AMFooImpl for an interface Foo when annotated. Now I want dagger to know binding Foo with FooImpl from my generated code. Adding simple @Inject to the constructor of generated class doesn’t work, I guess because the code is not available at compile time. How can I achieve this?Kshitij Patil
11/28/2022, 6:59 PMPaul Woitaschek
12/01/2022, 5:59 PMPaul Woitaschek
12/01/2022, 6:01 PMMarcello Galhardo
12/06/2022, 11:26 AM@Module
interface FooModule {
@Binds
fun FooImpl.bindFoo(): Foo
}
You may or may not want to generate the module code too. After that, you need to connect the module to the dagger Component.
If you use Anvil you can generate FooImpl with @ContributesBinding instead, and Anvil will generate the module for you.
If you use Hilt you can use InstallIn in the module to automatically connect to a given Component.