auto-di
Automatic dependency injection for Rust, backed by a global inventory
registry and async-safe initialization. The core API intentionally stays
small: use #[component] for constructor injection and #[bean] for factory
injection.
Components and constructor injection
use Arc;
use component;
#[component] supports these options:
name = "..."primaryscope = "singleton" | "prototype" | "request"eagerprofile = "development"condition = "ENV_KEY"orcondition = "ENV_KEY=value"post_construct = "async_method"pre_destroy = "async_method"
Constructors accept Arc<T>, Option<Arc<T>>, Vec<Arc<T>>, Provider<T>,
and Lazy<T>. Both sync and async constructors are supported.
The older #[service], #[repository], and #[singleton] names remain as
compatibility aliases, but they have no separate behavior.
Configuration beans
Beans do not need a configuration block. They can be declared in any module:
Use #[configuration] only when grouping related bean factories is useful.
Any ordinary type can also own bean methods. #[beans] only marks the impl for
macro expansion; the type is not required to represent configuration:
;
Components automatically discover nested beans:
;
Environment properties
Application and request scopes
async
let request = global_container?.request_context;
let bean = request..await?;
Active profiles come from comma-separated APP_PROFILES, or can be selected
explicitly with Container::with_profiles(...).