ayun_core/traits/
instance.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::{app, errors::ContainerError, support::type_name, Container, Result};

pub trait InstanceTrait: std::any::Any + Send + Sync {
    fn name() -> String {
        type_name::<Self>()
    }

    fn register(container: &Container) -> Result<Self, ContainerError>
    where
        Self: Sized;

    fn boot() -> Result<(), ContainerError>
    where
        Self: Sized,
    {
        Ok(())
    }

    fn facade() -> &'static Self
    where
        Self: Sized,
    {
        app()
            .resolve::<Self>()
            .unwrap_or_else(|err| panic!("{err}"))
    }
}