ambiguity resolution in scaldi

42 views
Skip to first unread message

Barys Ilyushonak

unread,
Jun 8, 2016, 7:51:59 AM6/8/16
to scaldi
Hi there,

Does scaldi support any feature for ambiguity resolutions? I mean I would like to prevent compillation/or running application if there is any ambiguityies in the bindings.

Lets take a look at the example. The class with defaul parameter

class SecureRandomIDGenerator(idSizeInBytes: Int = 128)

class MyModule extends Module {

binding to 1
binding to 42
   
  binding to injected
[SecureRandomIDGenerator]
}

I would assume the 42 will be used as the idSizeInBytes value. That becomes not so straight forward, if I have a lot of modules which are combined together.

Cheer,
Boris

Oleg Ilyenko

unread,
Jun 8, 2016, 2:26:12 PM6/8/16
to scaldi
Hi Boris,

Indeed, you are right, 42 would be used in this case. You can find son docs about it here:


When you compose modules together, they also follow simple lookup rules described here:


If you would like to avoid ambiguity, I would suggest to use additional identifiers for this. Hope this helps :)

Cheers,
Oleg

matthia...@deviceident.com

unread,
Jul 4, 2016, 5:15:44 AM7/4/16
to scaldi
Hi Oleg,

Thanks for the suggestion, however it doesn't solve the whole problem. The problem is
that one doesn't necessarily realise what's going on, i. e. that there is more than one Int
that might be injected in Barys' example. Perhaps it would be nice to have some feature
to blow up in such a case, i. e. have the inject method throw an exception when there's
more than one binding that satisfies the requirements. Would that be hard to add?

We've run into bugs caused by this behaviour more than once and it wasn't easy to debug…

Cheers,
Matthias

Alexandre Bedrytski

unread,
Jul 7, 2016, 3:20:37 AM7/7/16
to scaldi
Hi Mathhias,

I think it would be great to have a warning if there is such ambiguity (with a suggestion to use identifiers)
Please submit a issue to the github's issue tracker, I'll see if there is a possible solution.

Aliaksandr
Reply all
Reply to author
Forward
0 new messages