reactive_graph_command_impl/
command_system_impl.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4use springtime_di::Component;
5use springtime_di::component_alias;
6
7use reactive_graph_command_api::CommandManager;
8use reactive_graph_command_api::CommandSystem;
9use reactive_graph_command_api::CommandTypeProvider;
10use reactive_graph_lifecycle::Lifecycle;
11use reactive_graph_reactive_service_api::ReactiveSystem;
12use reactive_graph_type_system_api::TypeSystem;
13
14#[derive(Component)]
15pub struct CommandSystemImpl {
16    command_manager: Arc<dyn CommandManager + Send + Sync>,
17    command_type_provider: Arc<dyn CommandTypeProvider + Send + Sync>,
18
19    type_system: Arc<dyn TypeSystem + Send + Sync>,
20    reactive_system: Arc<dyn ReactiveSystem + Send + Sync>,
21}
22
23#[async_trait]
24#[component_alias]
25impl CommandSystem for CommandSystemImpl {
26    fn get_command_manager(&self) -> Arc<dyn CommandManager + Send + Sync> {
27        self.command_manager.clone()
28    }
29
30    fn get_command_type_provider(&self) -> Arc<dyn CommandTypeProvider + Send + Sync> {
31        self.command_type_provider.clone()
32    }
33
34    fn type_system(&self) -> Arc<dyn TypeSystem + Send + Sync> {
35        self.type_system.clone()
36    }
37
38    fn reactive_system(&self) -> Arc<dyn ReactiveSystem + Send + Sync> {
39        self.reactive_system.clone()
40    }
41}
42
43#[async_trait]
44impl Lifecycle for CommandSystemImpl {
45    async fn init(&self) {
46        self.command_type_provider.init().await;
47        self.command_manager.init().await;
48    }
49
50    async fn post_init(&self) {
51        self.command_type_provider.post_init().await;
52        self.command_manager.post_init().await;
53    }
54
55    async fn pre_shutdown(&self) {
56        self.command_manager.pre_shutdown().await;
57        self.command_type_provider.pre_shutdown().await;
58    }
59
60    async fn shutdown(&self) {
61        self.command_manager.shutdown().await;
62        self.command_type_provider.shutdown().await;
63    }
64}