rok_container/lib.rs
1//! IoC service container and dependency injection for the rok ecosystem.
2//!
3//! Provides a runtime type-map DI container, `#[derive(Injectable)]` for
4//! auto-wiring structs, and Axum extractors `Inject<T>` and `Bound<T>`.
5//!
6//! # Quick start
7//!
8//! ```rust,ignore
9//! use std::sync::Arc;
10//! use axum::{routing::get, Extension, Router};
11//! use rok_container::{Container, Inject};
12//!
13//! async fn hello(Inject(svc): Inject<GreetService>) -> String {
14//! svc.greet()
15//! }
16//!
17//! let container = Arc::new(Container::new());
18//! container.singleton(GreetService::new());
19//!
20//! let app = Router::new()
21//! .route("/hello", get(hello))
22//! .layer(Extension(Arc::clone(&container)));
23//! ```
24//!
25//! # Features
26//!
27//! | Feature | Enables |
28//! |---|---|
29//! | `axum` | [`Inject<T>`] extractor |
30//! | `postgres` | [`Bound<T>`] route-model binding (implies `axum`) |
31//! | `macros` | `#[derive(Injectable)]` re-export |
32
33pub mod container;
34pub mod error;
35
36#[cfg(feature = "axum")]
37pub mod inject;
38
39#[cfg(feature = "postgres")]
40pub mod bound;
41
42pub use container::Container;
43pub use error::ContainerError;
44
45#[cfg(feature = "axum")]
46pub use inject::Inject;
47
48#[cfg(feature = "postgres")]
49pub use bound::{Bound, BoundModel};
50
51#[cfg(feature = "macros")]
52pub use rok_container_macros::Injectable;