soph_core/traits/
application.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crate::{support::Container, traits::ServiceTrait, Result};
use async_trait::async_trait;

#[async_trait]
pub trait ApplicationTrait: 'static {
    type Service: ServiceTrait;

    #[cfg(feature = "migration")]
    type Migrator: sea_orm_migration::MigratorTrait;

    #[cfg(feature = "server")]
    fn with_routing() -> impl ServiceTrait;

    #[cfg(feature = "schedule")]
    fn with_schedule() -> impl ServiceTrait;

    #[cfg(feature = "console")]
    fn with_console() -> impl ServiceTrait;

    #[cfg(feature = "worker")]
    fn with_worker() -> impl ServiceTrait;

    fn configure() -> Result<()> {
        #[cfg(not(feature = "tracing"))]
        {
            use tracing_subscriber::layer::SubscriberExt;

            let subscriber = tracing_subscriber::registry()
                .with(tracing_subscriber::fmt::layer().with_target(false));
            let _ = tracing::subscriber::set_global_default(subscriber);
        }

        #[cfg(feature = "color-eyre")]
        color_eyre::install()?;

        Ok(())
    }

    async fn register(container: Container) -> Result<Container> {
        Ok(container)
    }

    async fn boot() {}
}