use std::fmt::{Display, Formatter};
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
/// How many times should a constructor be invoked?
pub enum Lifecycle {
/// The constructor for a `Singleton` type is invoked at most once.
///
/// As a consequence, there is at most one instance of `Singleton` types,
/// stored inside the server's global state.
Singleton,
/// The constructor for a `RequestScoped` type is invoked at most once for every incoming request.
///
/// As a consequence, there is at most one instance of `RequestScoped` types for every incoming
/// request.
RequestScoped,
/// The constructor for a `Transient` type is invoked every single time an instance of the type
/// is required.
///
/// As a consequence, there can be **multiple** instances of `Transient` types for every
/// incoming request.
Transient,
}
impl Display for Lifecycle {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s = match self {
Lifecycle::Singleton => "singleton",
Lifecycle::RequestScoped => "request-scoped",
Lifecycle::Transient => "transient",
};
write!(f, "{s}")
}
}