Hi, Been trying to figure out how to bind a singl...
# kodein
r
Hi, Been trying to figure out how to bind a singleton to multiple interfaces as we have a scenario where we sometimes want a specific type and other times everything of a different type. This is the best I’ve come up with and would love to know if this is a crazy idea or improvements? https://gist.github.com/rmaclean-ee/698b0bd08a49cbe8faef72165023a737
j
Disclaimer: I did not use the new 7.5.0 syntax yet 🙂 But wouldn't something like this work?
Copy code
bindSingleton<Consumable> { Petrol() }
inSet<Engine> { provider { instance<Consumable>() } }
Then your provider will always provide the singleton
r
your code seems pretty reasonable, but I don't get your use case exactly ?
r
The example code is pretty similar to my real world need. I have a bunch of pieces, which need to be started on startup (think polling and API); the
engines
- it would be great to just have them in a set so I can do that common start up over the set. I would also like to grab individual engines out from a unit testing perspective so that I can run tests against the code I care about. A different approach is different containers for unit tests and actual code, but have really found massive benefits from the module stuff and having a single container setup; as such wouldn’t like to tweak that too much.