boost-ext / di

C++14 Dependency Injection Library
https://boost-ext.github.io/di
1.16k stars 140 forks source link

How to forbid fundamental types and default initialization unless explicitly bound? #560

Closed netheril96 closed 6 months ago

netheril96 commented 7 months ago

I want the DI framework to find out the dependency graph problem at compile time if possible. However, in the default configuration, Boost.DI just value initializes ints, bools and other fundamental types. I want these to be explicitly supplied via instance binding, and I want it to be enforced.

I tried policies, but I couldn't figure out how to do what I want. The constructible policy seems only applicable to the arguments to the constructor. int has no constructor, and therefore is always allowed by the policy. I also tried to static assert the arity > 0, but then all explicitly bound ints fail the policy too.

I'm stumped. How to write such a policy? And even better, can Boost.DI have an easier way to enforce strictness?