Expand description
IoC service container and dependency injection for the rok ecosystem.
Provides a runtime type-map DI container, #[derive(Injectable)] for
auto-wiring structs, and Axum extractors Inject<T> and Bound<T>.
§Quick start
ⓘ
use std::sync::Arc;
use axum::{routing::get, Extension, Router};
use rok_container::{Container, Inject};
async fn hello(Inject(svc): Inject<GreetService>) -> String {
svc.greet()
}
let container = Arc::new(Container::new());
container.singleton(GreetService::new());
let app = Router::new()
.route("/hello", get(hello))
.layer(Extension(Arc::clone(&container)));§Features
| Feature | Enables |
|---|---|
axum | [Inject<T>] extractor |
postgres | [Bound<T>] route-model binding (implies axum) |
macros | #[derive(Injectable)] re-export |
Re-exports§
pub use container::Container;pub use error::ContainerError;