flow-di 0.1.0

A dependency injection framework for Rust inspired by C# AutoFac and Microsoft.Extensions.DependencyInjection
Documentation
/// Service lifetime enumeration
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum Lifetime {
    /// Singleton pattern - only one instance is created for the entire application lifetime
    /// Corresponds to Singleton in C# DI
    Singleton,

    /// Scoped pattern - shares the same instance within the same scope
    /// Corresponds to Scoped in C# DI
    Scoped,

    /// Transient pattern - creates a new instance for each request
    /// Corresponds to Transient in C# DI
    #[default]
    Transient,
}

impl Lifetime {
    /// Check if it's singleton lifetime
    pub fn is_singleton(&self) -> bool {
        matches!(self, Lifetime::Singleton)
    }

    /// Check if it's scoped lifetime
    pub fn is_scoped(&self) -> bool {
        matches!(self, Lifetime::Scoped)
    }

    /// Check if it's transient lifetime
    pub fn is_transient(&self) -> bool {
        matches!(self, Lifetime::Transient)
    }
}

impl std::fmt::Display for Lifetime {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Lifetime::Singleton => write!(f, "Singleton"),
            Lifetime::Scoped => write!(f, "Scoped"),
            Lifetime::Transient => write!(f, "Transient"),
        }
    }
}