pub trait Injectable:
Sized
+ Send
+ Sync
+ 'static {
type Provider: Provider<Self>;
const IS_SINGLETON: bool = true;
}Expand description
The primary trait for types that can be dependency-injected.
§Derivable
This trait is normally derived via #[derive(Injectable)]:
ⓘ
#[derive(Injectable)]
pub struct Database {
pool_size: usize,
}The derive macro generates:
- A
<Type>Providerstruct implementingProvider<Type> - All necessary
Extractcalls for constructor parameters - Lifecycle hook invocation (
post_construct,pre_destruct)
§Associated Types
Provider: The compile-time generated provider that knows how to construct this type, including all its transitive dependencies.
§Bounds
All injectable types must be Send + Sync + 'static to support
async construction and shared access across threads.
Provided Associated Constants§
Sourceconst IS_SINGLETON: bool = true
const IS_SINGLETON: bool = true
Whether this type is singleton-scoped (constructed once and cached).
Defaults to true. Transient-scoped types generated by the macro
override this to false so the cache is bypassed on every resolution.
Required Associated Types§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".