evant / kotlin-inject

Dependency injection lib for kotlin
Apache License 2.0
1.14k stars 51 forks source link

Interface Bindings #367

Closed jamesalee213 closed 3 months ago

jamesalee213 commented 3 months ago

Looking at the documentation, it looks like the only way to bind an interface type with a concrete class type is to write @Provides method in the @Component.

for example,

protected val RealHttp.bind: Http
    @Provides get() = this

or

@Provides
fun http(http: RealHttp): Http = http

proposed Enhancement

is it possible to provide a simpler way to do this when annotating the class? so that we don't have to add @Provides methods for these bindings? e.g.:

@Inject(boundType = Http::class)
class RealHttp : Http

or

@Inject @BindAs(Http::class)
class RealHttp : Http
evant commented 3 months ago

This looks like the same as https://github.com/evant/kotlin-inject/issues/212

jamesalee213 commented 3 months ago

This looks like the same as https://github.com/evant/kotlin-inject/issues/212

@evant it looks like that issue has been open for awhile.

I read the whole thread, but I'm not entirely sure what the course of action is from that issue. were you ok with the addition of:

but no one has implemented it yet?

evant commented 3 months ago

Correct, I'm open to contributions and otherwise helping make sure components can be extended for these kind of things, but it's not a priority for me to implement myself.