reactive_graph_net_git/
plugin.rs

1use reactive_graph_plugin_api::EntityComponentBehaviourRegistry;
2use reactive_graph_plugin_api::prelude::plugin::*;
3use reactive_graph_plugin_api::prelude::providers::*;
4
5use crate::behaviour::component::repository::RepositoryFactory;
6use reactive_graph_net_git_model::BEHAVIOUR_REPOSITORY;
7use reactive_graph_net_git_model::COMPONENT_BEHAVIOUR_REPOSITORY;
8
9export_plugin!({
10    "dependencies": [
11        { "name": "reactive-graph-std-base", "version": ">=0.10.0, <0.11.0" },
12        { "name": "reactive-graph-std-trigger", "version": ">=0.10.0, <0.11.0" },
13        { "name": "reactive-graph-sys-file", "version": ">=0.10.0, <0.11.0" },
14        { "name": "reactive-graph-net-http", "version": ">=0.10.0, <0.11.0" },
15    ]
16});
17
18#[injectable]
19pub trait ValuePlugin: Plugin + Send + Sync {}
20
21#[derive(Component)]
22pub struct ValuePluginImpl {
23    component_provider: Arc<dyn TypeProvider<Components> + Send + Sync>,
24
25    #[component(default = "component_provider_registry")]
26    component_provider_registry: Arc<dyn ComponentProviderRegistry + Send + Sync>,
27
28    entity_types_provider: Arc<dyn TypeProvider<EntityTypes> + Send + Sync>,
29
30    #[component(default = "entity_types_provider_registry")]
31    entity_type_provider_registry: Arc<dyn EntityTypeProviderRegistry + Send + Sync>,
32
33    #[component(default = "entity_component_behaviour_registry")]
34    entity_component_behaviour_registry: Arc<dyn EntityComponentBehaviourRegistry + Send + Sync>,
35}
36
37#[async_trait]
38#[component_alias]
39impl Plugin for ValuePluginImpl {
40    async fn activate(&self) -> Result<(), PluginActivationError> {
41        self.component_provider_registry.register_provider(self.component_provider.clone()).await;
42        self.entity_type_provider_registry.register_provider(self.entity_types_provider.clone()).await;
43
44        // Git Repository
45        let factory = Arc::new(RepositoryFactory::new(BEHAVIOUR_REPOSITORY.clone()));
46        self.entity_component_behaviour_registry
47            .register(COMPONENT_BEHAVIOUR_REPOSITORY.clone(), factory)
48            .await;
49
50        Ok(())
51    }
52
53    async fn deactivate(&self) -> Result<(), PluginDeactivationError> {
54        self.entity_component_behaviour_registry.unregister(&COMPONENT_BEHAVIOUR_REPOSITORY).await;
55        self.entity_type_provider_registry.unregister_provider(self.entity_types_provider.id()).await;
56        self.component_provider_registry.unregister_provider(self.component_provider.id()).await;
57        Ok(())
58    }
59}