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