injectable-rs-runtime 0.1.0

Runtime types and traits for the injectable-rs DI framework
Documentation
//! The `Injectable` trait — the primary marker for injectable types.
//!
/// Every type that wants to participate in the DI system must derive or
/// implement `Injectable`. The derive macro generates:
///
/// - An associated `Provider` type implementing [`Provider<T>`]
/// - Static dependency metadata for graph validation
/// - Lifecycle hook orchestration
use crate::Provider;

/// The primary trait for types that can be dependency-injected.
///
/// # Derivable
///
/// This trait is normally derived via `#[derive(Injectable)]`:
///
/// ```rust,ignore
/// #[derive(Injectable)]
/// pub struct Database {
///     pool_size: usize,
/// }
/// ```
///
/// The derive macro generates:
/// - A `<Type>Provider` struct implementing `Provider<Type>`
/// - All necessary `Extract` calls 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.
pub trait Injectable: Send + Sync + Sized + 'static {
    /// The provider type that knows how to construct `Self`.
    ///
    /// Generated by the `#[derive(Injectable)]` macro. Each provider
    /// statically encodes its dependency tree through `Extract` calls.
    type Provider: Provider<Self>;

    /// 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.
    const IS_SINGLETON: bool = true;
}