use std::sync::Arc;

use crate::{
    service::{Service, ServiceProvider},
    service_lifetime::ServiceLifetime,
};

/// Factory function used to build a service instance on demand.
///
/// A plain `fn` pointer is used instead of a boxed closure because every
/// registration goes through `T::init`, which is a regular function. Storing
/// a `fn` avoids the per-registration heap allocation and per-resolution
/// `Arc` clone that a `Arc<dyn Fn(..)>` would require.
pub type ServiceInitFn = fn(&dyn ServiceProvider) -> Arc<dyn Service>;

/// Registration record stored in the [`crate::service_container::ServiceContainer`]
/// for every declared service.
#[derive(Clone)]
pub struct ServiceDefinition {
    pub lifetime: ServiceLifetime,
    pub init: ServiceInitFn,
}
