6 releases (3 breaking)
Uses new Rust 2024
| new 0.4.0 | Mar 6, 2026 |
|---|---|
| 0.3.0 | Mar 3, 2026 |
| 0.2.1 | Mar 3, 2026 |
| 0.2.0 | Feb 24, 2026 |
| 0.1.1 | Feb 24, 2026 |
#2770 in Rust patterns
Used in injectium-salvo
31KB
431 lines
injectium
A minimal dependency-injection implementation for Rust.
Installation
cargo add injectium
Quick Start
use injectium::{Injectable, cloned, container};
#[derive(Clone)]
struct Db {
conn: String,
}
#[derive(Injectable)]
struct Service {
db: Db,
}
// At startup, build the container
let c = container! {
providers: [
cloned(Db { conn: "postgres://localhost".into() }),
],
};
// Validate everything is wired up
c.validate();
// Later, resolve services
let svc = Service::from_container(&c);
Documentation
See docs.rs for full API documentation.
Crates
| Crate | Description |
|---|---|
injectium |
Main crate with derive macro |
injectium-core |
Core container implementation |
injectium-macro |
Procedural macros |
injectium-salvo |
Salvo web framework integration |
License
Dependencies
~83KB