I'm using getAll<>() to retrieve a list of d...
# koin
j
I'm using getAll<>() to retrieve a list of dependencies, but I also need the named value for each. How can I accomplish this? My goal is to create a map where the key is the named value and the value is the dependency itself.
w
Use a sealed class or enum instead of string names
j
Not possible in my case. I'm implementing deep links in my application along with Slack's Circuit. The map I'm creating uses the deep link string representation as keys, which precludes the use of enums or sealed classes for this purpose.
w
No it doesn’t, use the string value as an enum or sealed class property 🙂
j
Can you share a skeleton code example if possible? 🙂
w
The docs are good, and have examples of adding properties to enums
j
I meant how would I get them along with getAll to create a map as opposed to using strings.
w
Sorry, that’s for you to figure out
If it were me I would never use strings at all, they are not safe, and any solution that chooses to use strings for important things like navigation or parameters is asking for pain
j
Oh, I see what you mean. I was under the impression that using enums instead of strings would allow me to access them through a Koin API, but it seems it was more of an architectural suggestion. Thanks for the suggestion. 🙏🏻
w
No, my suggestion was to take your strings, and wrap them in an Enum
👍 1
then use the enum to fetch the dependencies from koin
you can use Enums/types as qualifiers
If you are stuck using Strings for things, you can do things to make them more safe 🙂
That or something else with your architecture should change so that you can handle all of this with a single
factory
and a parameter
then you can handle the mess within the implementation class
👍 1