Hi everyone,
I’m writing a small library that might be used by other developers and I’m facing some doubts how to design integration of this library with 3rd party code (in my case, Dagger DI).
For example, I want to provide interoperability with one or a Set
of javax.inject.Provider
and for that, I want to convert it to MyFactory
. Looking at the standard library I found two ways of doing it:
- Create a
.toMyFactory
extension function for aProvider
and aSet<Provider>
which returns aMyFactory
instance. - Create a
myFactoryOf
which receives as parameter aProvider
or aSet<Provider
and builds aMyFactory
instance.
Code sample:
fun test(provider: Provider<MyClass>, providers: Set<Provider<MyClass>>) {
// Using `.toMyFactory`
val fromInstance1 = provider.toMyFactory()
val fromSet1 = providers.toMyFactory()
// Using `myFactoryOf`
val fromInstance2 = myFactoryOf(provider)
val fromSet2 = myFactoryOf(providers)
}
What option is more Kotlin-friendly to provide this type of integration?