r/cpp • u/Acrobatic-Stable2537 n0F4x • Jun 25 '26
C++23 Dependency Injection library with automatic dependency building
I open-sourced my dependency injection library.
Link: https://github.com/n0F4x/redi
This was developed for my game engine.
- feature-rich dependency configuration
- optimized for fast compile time
- helpful error messages when a cyclic dependency is detected
- dependencies are automatically constructed - no need to register them by hand
I am giving this project to the community so that everybody can benefit. This kind of approach is mostly useful when dealing with intricate systems, such as a plugin system. I welcome all kinds of feedback, as this was mostly a learning opportunity for me. If you'd like to use this in your project but don't have access to the required compiler features, let me know, and I'll see if I can reduce the requirements.
View all comments
Show parent comment
1
u/rahem027 Jun 27 '26
Even if IDE are not available, changing the order of parameters in constructors is rare enough to not depend on an entire DI framework just to be able to do that. Specially when you can grep through all the usages and change them one by one.
I have worked on million line projects (not C++ though). It is not ceremony to pass input to functions. Its literally the job of the caller. It might not be "nice" to pass parameters 3 levels deep. Which is true. But it forces you to think does the code really need to pass these params 3 levels below? Or are we doing it just because we are not writing code that does not need to do this?
DI is at best, a band-aid on a fundamental coding problem. Its a solution looking for problems instead of solving them. Now one may argue that it is not always possible to refactor large code bases specially when people are involved and I would agree with you. But, does not change the fact, that the code is not designed properly. And DI is just a band-aid instead of fixing the core problem. (And to re iterate again, it might not be possible because of a lot of factors, both technical and human, but it is still a band-aid).