Is it possible to remove the ambiguity to provide ...
# dagger
i
Is it possible to remove the ambiguity to provide a ListProcessor just by providing two distinct lists?
s
If I understand your question correctly, you need a qualifier: https://dagger.dev/users-guide.html Read the Qualifier section
i
@Named is already a qualifier. The problem is that I have to build two distinct objects that depends on two distinct lists (with 2 distinct qualifiers)
I don’t think it’s possible to explain it better than the code. Baiscally I would like to get rid of the two provideListProcessor providers, if possible.
But I think it’s not possible. Just checking here to make sure.
s
May be you can create a
ListProcessorFactory
?
i
It’s possible, so I would need to do something like: ProcessorFactory(@Named(“LIST_1”) list1: List<String>, @Named(“LIST_2" list2: List<String>)
but the overhead is very similar
If I need to create N processors, I would need to provide N lists + N processors
Or, add in the factory line
I think Java would require template arguments, like C++ to solve this kind of ambiguity.
I can make some magic with generics to avoid that, but i don’t think it will worth it.
g
No, you cannot avoid having N processor if you want N lists as dependencies in a single scope (so those lists can be used somewhere else) As was suggested above, you can instead inject processor factory to list provider and return processor instead of the list, if you don't use this list anywhere else
👍 1