rok-container 0.3.4

IoC service container and dependency injection for the rok ecosystem
Documentation
//! 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
//!
//! ```rust,ignore
//! 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 |

pub mod container;
pub mod error;

#[cfg(feature = "axum")]
pub mod inject;

#[cfg(feature = "postgres")]
pub mod bound;

pub use container::Container;
pub use error::ContainerError;

#[cfg(feature = "axum")]
pub use inject::Inject;

#[cfg(feature = "postgres")]
pub use bound::{Bound, BoundModel};

#[cfg(feature = "macros")]
pub use rok_container_macros::Injectable;