A high-performance, lock-free dependency injection container for Rust. Type-safe, zero-config, and built for modern concurrent applications.
[dependencies]
dependency-injector = "0.1"
Built from the ground up for performance and ergonomics in modern Rust applications.
Uses DashMap for ~10x faster concurrent access compared to RwLock-based containers.
Compile-time type checking with zero runtime overhead. Errors caught before deployment.
Any Send + Sync + 'static type is automatically injectable. No boilerplate required.
Hierarchical scopes with full parent chain resolution. Perfect for request-scoped services.
Singleton, lazy singleton, and transient lifetimes. Choose what fits your use case.
Optional tracing integration for debugging and monitoring service resolution.
Get started in seconds with a clean, ergonomic interface.
use dependency_injector::Container;
// Define your services
#[derive(Clone)]
struct Database { url: String }
#[derive(Clone)]
struct UserService { db: Database }
fn main() {
// Create container
let container = Container::new();
// Register services
container.singleton(Database {
url: "postgres://localhost".into()
});
// Lazy initialization
container.lazy(|| UserService {
db: container.get().unwrap()
});
// Resolve anywhere
let users = container.get::<UserService>().unwrap();
}
No traits to implement, no macros to apply. Just use your types directly.
Returns Arc<T> for zero-copy sharing across threads and components.
Services created on first access. No wasted initialization.
Create child scopes to override services for testing without affecting parents.
Add Armature DI to your project and experience dependency injection done right.