https://kotlinlang.org logo
Title
d

Davide Giuseppe Farella

04/25/2023, 12:14 PM
Hello people. Is this supposed to be supported:
@Named("abc")
annotation class Abc
It doesn't seem to be working consistently, as declaring this doesn't work
class Module {

  @Factory
  @Abc
  fun abc() = "abc"
}
While this does work
class Module {

  @Factory
  @Named("abc")
  fun abc() = "abc"
}
I have other cases where it worked, I don't remember where, I could check if needed
a

arnaud.giuliani

05/09/2023, 2:58 PM
it's not like dagger, that is generating everything compile time. Just define a named on a definition
just use
@Named()
on needed definition, and function/constructor arguments that you need to pass
d

Davide Giuseppe Farella

05/09/2023, 3:00 PM
I forget to correct my message
I have other cases where it worked, I don’t remember where, I could check if needed
Afterwards I realized I was providing the wrong
Int
in “other cases” 😄 But if I’m not mistaken that works on Dagger and I find it very clean 🙂
a

arnaud.giuliani

05/09/2023, 3:10 PM
you don't need to define your own annotation with Koin, just use the
named
annotation or function where you need it
d

Davide Giuseppe Farella

05/09/2023, 3:12 PM
I don't need, but I would like to :) I prefer
@MyQualifier
over
@Named(MY_QUALIFIER)
Just my opinion ofc
a

arnaud.giuliani

05/09/2023, 4:51 PM
yes, because you can use static strings also 🙂