Hi, I have a class which requires multiple depende...
# koin
s
Hi, I have a class which requires multiple dependencies to instantiate, for example, Dependencies A, B, and C. A is a dependency annotated on the class itself, while B and C are defined using the DSL approach. However, when I assemble the APK, I encounter an error stating that the definitions for B and C are missing. Are annotations and the DSL approach not compatible with each other?
Copy code
@Single
class ScalefusionRepositoryImpl(
    private val foo: Food, // Class annottaions with @Factory
    private val bar: Bar, // Defined in the Kotlin DSL module
    private val sugar: Sugar, // Defined in the Kotlin DSL module
){
  ...
}
Annotated Class
Copy code
@Factory
class Foo{
   ...
}
Kotlin DSL Module
Copy code
val coreModule = module {
    factoryOf(::Bar)
    factoryOf(::Sugar)

}
Error
Copy code
Missing Definition type 'com.x.y.data.mapper.TestMapper' for 'com.x.y.data.repository.ScalefusionRepositoryImpl'. Fix your configuration to define type 'TestMapper'.
P.S.: Bar and Sugar classes are implementing a generic interface. The only way to bind them with a generic interface is through the Koin DSL approach approach. However, with the annotations, the only way to bind them is using the @Named annotation, which is not the best as I have to pass the names everywhere.
p
You need to provide them using annotations. You can also invoke koin to inject them inside your provide function. Koin annotations doesn't see the DSL in project.
s
Koin annotations doesn't see the DSL in project.
👍 Can you please elaborate on what you said below? I didn't fully understand
Copy code
You can also invoke koin to inject them inside your provide function.