Josh Feinberg
09/30/2023, 5:20 PMInterfaceA
and InterfaceB
. i have one object that needs a set of InterfaceA
implementations and another that needs an implementation of InterfaceB
. not sure the best way to handle this (code in 🧵 in case this makes no sense)Josh Feinberg
09/30/2023, 5:23 PM@Component
abstract class AppComponent {
@IntoSet
@Provides
fun provideInterfaceA(): ? {
return MyObject()
}
@Provides
fun provideStuff(interfaceAs: Set<InterfaceA>) {
}
@Provides
fun provideOtherStuff(interfaceB: InterfaceB) {
...
}
}
class MyObject : InterfaceA, InterfaceB {
...
}
Josh Feinberg
09/30/2023, 5:24 PMprovideOtherStuff
accept a Set<InterfaceA>
and then just do interfaceAs.filterInstanceOf { InterfaceB }
or somethingJosh Feinberg
09/30/2023, 5:26 PMIntoSet
take a parameter for an object type so I could do
@IntoSet(InterfaceA::class)
@Provides
fun provideInterfaceB(): InterfaceB {
return MyObject()
}
which would create the set binding for InterfaceA
and the provides method for InterfaceB
Asapha
10/15/2023, 5:56 PM@Component
abstract class AppComponent {
// Provide the impl
@Provides
fun provideMyObject(): MyObject {
return MyObject()
}
// Then bind it to whatever interfaces you need
@IntoSet
@Provides
fun provideInterfaceA(myObject: MyObject): InterfaceA {
return myObject
}
@Provides
fun provideInterfaceB(myObject: MyObject): InterfaceB {
return myObject
}
@Provides
fun provideStuff(interfaceAs: Set<InterfaceA>) {
}
@Provides
fun provideOtherStuff(interfaceB: InterfaceB) {
...
}
}
Josh Feinberg
10/15/2023, 6:07 PMMyObject
inherits from both InterfaceA
and interfaceB
though and hard code that. with your solution, i'm not sure how i'd do a test replacement other than making MyObject
inherit from a third interface so that i can inject that so that i can inject a fake for my tests