Available on crate feature
di only.Expand description
Compile-time dependency injection infrastructure.
Build dependency graphs that are resolved at compile time for zero runtime overhead.
§Example
ⓘ
use allframe::di::{ContainerBuilder, Provider};
let container = ContainerBuilder::new()
.register::<DatabasePool>()
.register::<UserRepository>()
.build();Dependency Injection Infrastructure
This module provides compile-time dependency injection with support for:
- Async initialization
- Explicit dependency declaration
- Singleton and transient scoping
- Environment-based configuration
§Example
ⓘ
use allframe_core::di::{Provider, Scope, DependencyError};
use allframe_macros::di_container;
#[di_container]
struct AppContainer {
#[provide(from_env)]
config: Config,
#[provide(singleton, async)]
#[depends(config)]
database: DatabasePool,
#[provide(transient)]
service: MyService,
}
// Generated async build method
let container = AppContainer::build().await?;Re-exports§
pub use lazy::*;
Modules§
- lazy
- Lazy initialization for DI containers
Structs§
- Container
Builder - Builder for constructing dependency containers with explicit ordering
- Dependency
Registry - A type-erased container for storing dependencies
Enums§
- Dependency
Error - Error type for dependency injection operations
- Scope
- Scope determines the lifecycle of a dependency
Traits§
- Async
Init - Trait for async initialization
- Async
Init With - Trait for types that can be initialized with dependencies
- FromEnv
- Trait for types that can be loaded from environment variables
- Provider
- Trait for types that can provide dependencies
Functions§
- env_var
- Helper to load a value from an environment variable
- env_
var_ opt - Helper to load an optional value from an environment variable
- env_
var_ or - Helper to load a value from an environment variable with a default
- env_
var_ parse - Helper to parse a value from an environment variable