//! Companion trait for the `#[service]` proc-macro.
//!
//! A type that implements [`ServiceImpl`] declares how to construct
//! itself from a [`Container`]. The
//! [`#[service]`](https://crates.io/crates/kick-rs-macros) proc-macro
//! generates this impl automatically from a struct definition.
//!
//! Hand-written impls are also fine — useful when a service needs a
//! custom constructor that the macro can't infer (e.g., picking one of
//! several backing implementations at runtime).
//!
//! ```ignore
//! use kick_rs_core::{Container, ServiceImpl};
//! use std::sync::Arc;
//!
//! pub struct UserService {
//!     repo: Arc<UserRepository>,
//! }
//!
//! impl ServiceImpl for UserService {
//!     fn build(c: &Container) -> Arc<Self> {
//!         Arc::new(UserService { repo: c.resolve::<UserRepository>() })
//!     }
//! }
//! ```
//!
//! Once a type is `ServiceImpl`, [`ModuleBuilder::service`](crate::ModuleBuilder::service)
//! registers it with one call:
//!
//! ```ignore
//! define_module("users")
//!     .service::<UserService>()
//!     .build();
//! ```

use crate::Container;
use std::sync::Arc;

/// Types whose construction can be expressed purely in terms of a
/// [`Container`] lookup. Generated by `#[service]` for typical
/// dependency-injection services; can be hand-implemented for custom
/// construction logic.
pub trait ServiceImpl: Send + Sync + Sized + 'static {
    /// Build a new instance of this service by resolving its
    /// dependencies from `c`.
    fn build(c: &Container) -> Arc<Self>;
}
