Sagar Khurana
10/07/2024, 11:05 AM@Factory
class Foo: Mapper<X, Y> {
override fun convert(data: X): Y {
return ...
)
}
}
and, Mapper interface
interface Mapper<in In, out Out> {
fun convert(data: In): Out
}
I'm using the Koin annotations. When I use the annotation with just, let's say, @Factory
, Koin automatically maps the dependency to provide the Mapper::class
. However, I want to specifically map the dependency to the Mapper<X, Y> type. Using the @Named
annotation achieves my goal, but I'm wondering if there's a better way to do itAlexandru Caraus
10/07/2024, 11:31 AMSagar Khurana
10/07/2024, 12:37 PMOnly classes are allowed on the left hand side of a class literal
Alexandru Caraus
10/07/2024, 1:26 PMAlexandru Caraus
10/07/2024, 1:26 PMSagar Khurana
10/07/2024, 1:31 PMOnly classes are allowed on the left hand side of a class literal
😢 , in the above example you shared use case is a interface tooSagar Khurana
10/07/2024, 1:32 PMAlexandru Caraus
10/07/2024, 1:44 PMSagar Khurana
10/07/2024, 1:44 PMAlexandru Caraus
10/07/2024, 1:54 PMAlexandru Caraus
10/07/2024, 3:55 PMAlexandru Caraus
10/07/2024, 3:55 PMAlexandru Caraus
10/07/2024, 5:49 PMSagar Khurana
10/07/2024, 5:49 PMFollowing works, and you don't need, @namedSure, Koin works well when there is only one Foo, but when there are multiple implementation classes, Koin doesn't know which one to inject without the @named annotation.
Sagar Khurana
10/07/2024, 5:51 PMAlexandru Caraus
10/07/2024, 5:53 PMAlexandru Caraus
10/07/2024, 5:53 PMAlexandru Caraus
10/07/2024, 5:55 PMAlexandru Caraus
10/07/2024, 5:57 PMSagar Khurana
10/07/2024, 6:04 PMAlexandru Caraus
10/07/2024, 6:05 PMarnaud.giuliani
10/15/2024, 2:18 PMThen, from the discussion, there are two possible ways to achieve this:
1. DSL
2. Using @named annotation for annotations approachEffectively types are erased at runtime 👍