Hi everyone,
I’ve been experimenting with implementing compile-time Dependency Injection in Rust using procedural macros and wanted to share the idea and get feedback from the community.
The goal of the experiment is to explore whether a DI-style architecture can be implemented in Rust while preserving Rust’s core principles:
- zero runtime overhead
- compile-time wiring of components
- no runtime container
- strong type safety
Instead of resolving dependencies dynamically, the procedural macro generates an ApplicationContext that wires components together at compile time.
The repository contains several small examples showing the idea step by step, including:
- manual initialization vs DI-style initialization
- compile-time wiring of components
- polymorphic services
- multiple application profiles
Example idea (simplified):
Each profile produces its own ApplicationContext, where dependencies are wired automatically.
The project is mainly an educational exploration, not a production-ready framework.
Repository:
I’m also working on a longer article explaining the motivation and design decisions behind the approach.
I’d really appreciate feedback, especially regarding:
- whether this approach feels idiomatic in Rust
- macro design improvements
- better ways to handle component discovery and wiring
Thanks!
