On 2014-07-27, 5:46 PM, Kris wrote:
Hi Sohail,
So that example is fine when it comes to a single type, but I have hundreds of types that are separately compiled. Creating an injector for each type is cumbersome. Is there a way you can come up with a solution that is generic? I know you suggested type lists but that is too much of a burden.
[snip]
3) mixed runtime/compile time solution, which, at some point, I made proof-of-concept of, but I did give up on in the end, due to the fact I wasn't able to get compile time checking working in many cases, runtime overhead and implementation complexity didn't help either - anyway such solution might be easily implemented on top of current library, proof-of-concept and the idea might be found in: https://github.com/krzysztof-jusiak/di_runtime_injector
di::injector<> injector; injector.install( di::bind
() ); injector.install( di::bind<int>::to(42) ); injector.create<app>();
[snip]
Thanks:) Anyway IMHO runtime binding may have some abilities of static checking, but exceptions will have to be thrown there either way. Separately compiling bindings definitely might be achieved with static checking for example with usage of forward declarations or composition root approach.
It doesn't need to do the fancy stuff, though it is (almost?) all
possible in my experience. Somehow, Guice survives by detecting things
at runtime so I would take from their experience that it is not a
completely terrible proposition. Is it possible to automatically convert
a static injector to a dynamic one? This might be the best of both
worlds. That is, something like this:
di::injector<>
SomeModule() {
return di::make_injector(
di::bind