reactive_graph_behaviour_service_api/
relation_behaviour_registry.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4use springtime_di::injectable;
5
6use reactive_graph_behaviour_model_api::prelude::*;
7use reactive_graph_graph::RelationInstanceId;
8use reactive_graph_graph::RelationTypeId;
9use reactive_graph_lifecycle::Lifecycle;
10use reactive_graph_reactive_model_impl::ReactiveRelation;
11
12#[injectable]
13#[async_trait]
14pub trait RelationBehaviourRegistry: Send + Sync + Lifecycle {
15    /// Registers a factory for creating relation behaviours.
16    fn register(&self, relation_behaviour_ty: RelationBehaviourTypeId, factory: Arc<dyn BehaviourFactory<RelationInstanceId, ReactiveRelation> + Send + Sync>);
17
18    /// Unregisters a factory for creating relation behaviours.
19    fn unregister(&self, relation_behaviour_ty: &RelationBehaviourTypeId);
20
21    /// Returns all relation behaviours.
22    fn get_all(&self) -> Vec<RelationBehaviourTypeId>;
23
24    /// Returns the relation behaviour factories for the given entity type.
25    fn get(&self, relation_ty: &RelationTypeId) -> Vec<Arc<dyn BehaviourFactory<RelationInstanceId, ReactiveRelation> + Send + Sync>>;
26
27    /// Returns the relation behaviour for the given behaviour type if the relation behaviour exists.
28    fn get_factory_by_behaviour_type(
29        &self,
30        behaviour_ty: &BehaviourTypeId,
31    ) -> Option<Arc<dyn BehaviourFactory<RelationInstanceId, ReactiveRelation> + Send + Sync>>;
32
33    /// Returns the relation behaviours for the given entity type.
34    fn get_behaviour_types(&self, relation_ty: &RelationTypeId) -> Vec<RelationBehaviourTypeId>;
35
36    /// Returns the relation behaviour for the given behaviour type if the relation behaviour exists.
37    fn get_by_behaviour_type(&self, behaviour_ty: &BehaviourTypeId) -> Option<RelationBehaviourTypeId>;
38
39    /// Returns the count of relation behaviours.
40    fn count(&self) -> usize;
41}