Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
For an example, look at the last few lines of the main class in a program I write, starting near the bottom of this file: https://github.com/rsjaffe/MIDI2LR/blob/master/src/application/Main.cpp at lines 488 or so, where the members of the main program class are declared. There are multiple lines of communication being set up, program configuration classes, etc. The members are constructed in the order they are declared, and you can see that some of the later members take references to the earlier members in their constructors. This is the dependency injection, and by doing it this way, I am forced to declare and construct the dependencies before I construct the members using those dependencies. And, since destruction goes in the opposite direction (bottom up), the dependencies remain valid until after all the classes using the dependencies are gone.
Funny you mention dependency injection, proposed Boost.DI shall be up for Boost peer review probably in March. https://boost-ext.github.io/di/