auto-di
Automatic dependency injection for Rust, backed by a global inventory
registry and async-safe initialization. The core API intentionally stays
small: use #[singleton] for constructor injection and #[provider] for factory
injection.
Components and constructor injection
use Arc;
use singleton;
#[singleton] 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.
Providers
Providers can be declared in any module:
Singletons automatically discover nested providers:
;
Environment properties
Application and request scopes
async
let request = global_container?.request_context;
let dependency = request..await?;
Active profiles come from comma-separated APP_PROFILES, or can be selected
explicitly with Container::with_profiles(...).