ayun_core/traits/
instance.rs

1use crate::{
2    error::ContainerError,
3    support::{app, type_name, Container},
4    Result,
5};
6
7pub trait InstanceTrait: std::any::Any + Send + Sync {
8    fn name() -> String {
9        type_name::<Self>()
10    }
11
12    fn register(container: &Container) -> Result<Self, ContainerError>
13    where
14        Self: Sized;
15
16    fn boot() -> Result<(), ContainerError>
17    where
18        Self: Sized,
19    {
20        Ok(())
21    }
22
23    fn cleanup() -> Result<(), ContainerError> {
24        Ok(())
25    }
26
27    fn facade() -> &'static Self
28    where
29        Self: Sized,
30    {
31        app()
32            .resolve::<Self>()
33            .unwrap_or_else(|err| panic!("{err}"))
34    }
35}