TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25485 18
A policy-based Dependency Injection framework for C++26

# Looking for feedback on a policy-based compile-time DI framework for C++20

I've been working on a compile-time Dependency Injection framework for modern C++:

https://github.com/steumarok/cppdimanager

The main idea is a policy-based resolution pipeline where object creation, dependency injection, casting, lifetime management and scope creation are handled by independent compile-time policies.

Unlike traditional DI containers that are primarily organized around service lifetimes, the framework is built around the following pipeline:

Requested Type
↓
Resolution Policy
↓
Creation Policy
↓
Injection Policy
↓
Cast Policy
↓
Returned Type


Current features:

- Constructor injection
- Member injection
- Interface-to-implementation mapping
- Hierarchical containers
- Request-scoped dependencies
- Scoped object lifetimes
- Automatic factory injection (std::function<T()>)
- Compile-time registries
- Configurable resolution and creation policies

Example web application:

https://github.com/steumarok/cppdimanager/blob/main/example.cpp

I'm particularly interested in feedback about:

- Overall API design
- Lifetime and scope management
- Policy architecture
- Compile-time vs runtime trade-offs
- Potential simplifications
- Missing features compared to existing DI frameworks

Suggestions and criticism are very welcome.

https://redd.it/1udrt86
@r_cpp
More from @r_cpp
  1. Sep 29, 2026Boost.Graph 1.95 will be C++17 Dear Boost.Graph community, In two release cycles (Boost re…
  2. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  3. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  4. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  5. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  6. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →