I'm working in a codebase that already has a simpl...
# dagger
c
I'm working in a codebase that already has a simple dagger/hilt module setup as such:
Copy code
@Module
@InstallIn(SingletonComponent)
interface MyModule {
  companion object {
    @Provides
    @Singleton
    fun provideThing(builder: MyBuilder): Thing = builder.build()
  }
}
I'm not sure of the reason why this is an interface with a companion object. Can someone explain why? Additionally... if I wanted to add a new provides method for a simple Foo object would I just do @Provides fun provideFoo() = Foo() inside of the companion object, or outside of the companion?
n
I would guess they either use to have a
@Binds
method defined in the interface or they plan to have one added later?
Additionally... if wanted to add a nevw provides method for a simple Foo object would just do
@Provides fun provideFoo() = Foo()
inside of the companion object, or outside of the companion?
Inside the companion object! Although if Foo is an object you own you should just update its constructor to use
@Inject
and avoid the provides method entirely.
c
they plan to have one added later?
Gotcha. so almost like "future proofed" in a way
Inside of the companion object
Awesome. thank you! and good point on just putting @Inject. lol.
nod 1